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 1085 1085: def self.create(arg) 1086: case arg 1087: when Name 1088: return arg 1089: when String 1090: return Name.new(Label.split(arg), /\.\z/ =~ arg ? true : false) 1091: else 1092: raise ArgumentError.new("cannot interpret as DNS name: #{arg.inspect}") 1093: end 1094: end
True if this name is absolute.
# File lib/resolv.rb, line 1108 1108: def absolute? 1109: return @absolute 1110: 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 1133 1133: def subdomain_of?(other) 1134: raise ArgumentError, "not a domain name: #{other.inspect}" unless Name === other 1135: return false if @absolute != other.absolute? 1136: other_len = other.length 1137: return false if @labels.length <= other_len 1138: return @labels[-other_len, other_len] == other.to_a 1139: 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 1168 1168: def to_s 1169: return @labels.join('.') 1170: end