| 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 1052
1052: def self.create(arg)
1053: case arg
1054: when Name
1055: return arg
1056: when String
1057: return Name.new(Label.split(arg), /\.\z/ =~ arg ? true : false)
1058: else
1059: raise ArgumentError.new("cannot interpret as DNS name: #{arg.inspect}")
1060: end
1061: end
True if this name is absolute.
# File lib/resolv.rb, line 1075
1075: def absolute?
1076: return @absolute
1077: 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 1100
1100: def subdomain_of?(other)
1101: raise ArgumentError, "not a domain name: #{other.inspect}" unless Name === other
1102: return false if @absolute != other.absolute?
1103: other_len = other.length
1104: return false if @labels.length <= other_len
1105: return @labels[-other_len, other_len] == other.to_a
1106: 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 1135
1135: def to_s
1136: return @labels.join('.')
1137: end