Class | Resolv::DNS::Name |
In: |
lib/resolv.rb
|
Parent: | Object |
A representation of a DNS name.
== | -> | eql? |
Creates a new DNS name from arg. arg can be:
Name: | returns arg. |
String: | Creates a new Name. |
# File lib/resolv.rb, line 1053 1053: def self.create(arg) 1054: case arg 1055: when Name 1056: return arg 1057: when String 1058: return Name.new(Label.split(arg), /\.\z/ =~ arg ? true : false) 1059: else 1060: raise ArgumentError.new("cannot interpret as DNS name: #{arg.inspect}") 1061: end 1062: end
True if this name is absolute.
# File lib/resolv.rb, line 1076 1076: def absolute? 1077: return @absolute 1078: end
Returns true if other is a subdomain.
Example:
domain = Resolv::DNS::Name.create("y.z") p Resolv::DNS::Name.create("w.x.y.z").subdomain_of?(domain) #=> true p Resolv::DNS::Name.create("x.y.z").subdomain_of?(domain) #=> true p Resolv::DNS::Name.create("y.z").subdomain_of?(domain) #=> false p Resolv::DNS::Name.create("z").subdomain_of?(domain) #=> false p Resolv::DNS::Name.create("x.y.z.").subdomain_of?(domain) #=> false p Resolv::DNS::Name.create("w.z").subdomain_of?(domain) #=> false
# File lib/resolv.rb, line 1101 1101: def subdomain_of?(other) 1102: raise ArgumentError, "not a domain name: #{other.inspect}" unless Name === other 1103: return false if @absolute != other.absolute? 1104: other_len = other.length 1105: return false if @labels.length <= other_len 1106: return @labels[-other_len, other_len] == other.to_a 1107: end
returns the domain name as a string.
The domain name doesn‘t have a trailing dot even if the name object is absolute.
Example:
p Resolv::DNS::Name.create("x.y.z.").to_s #=> "x.y.z" p Resolv::DNS::Name.create("x.y.z").to_s #=> "x.y.z"
# File lib/resolv.rb, line 1136 1136: def to_s 1137: return @labels.join('.') 1138: end