Class: Resolv::DNS::Name
- Inherits:
-
Object
- Object
- Resolv::DNS::Name
- Defined in:
- lib/resolv.rb
Overview
A representation of a DNS name.
Class Method Summary collapse
-
.create(arg) ⇒ Object
Creates a new DNS name from
arg
.
Instance Method Summary collapse
-
#==(other) ⇒ Object
(also: #eql?)
:nodoc:.
-
#[](i) ⇒ Object
:nodoc:.
-
#absolute? ⇒ Boolean
True if this name is absolute.
-
#hash ⇒ Object
:nodoc:.
-
#initialize(labels, absolute = true) ⇒ Name
constructor
:nodoc:.
-
#inspect ⇒ Object
:nodoc:.
-
#length ⇒ Object
:nodoc:.
-
#subdomain_of?(other) ⇒ Boolean
Returns true if
other
is a subdomain. -
#to_a ⇒ Object
:nodoc:.
-
#to_s ⇒ Object
returns the domain name as a string.
Constructor Details
#initialize(labels, absolute = true) ⇒ Name
:nodoc:
1211 1212 1213 1214 |
# File 'lib/resolv.rb', line 1211 def initialize(labels, absolute=true) # :nodoc: @labels = labels @absolute = absolute end |
Class Method Details
.create(arg) ⇒ Object
Creates a new DNS name from arg
. arg
can be:
- Name
-
returns
arg
. - String
-
Creates a new Name.
1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 |
# File 'lib/resolv.rb', line 1200 def self.create(arg) case arg when Name return arg when String return Name.new(Label.split(arg), /\.\z/ =~ arg ? true : false) else raise ArgumentError.new("cannot interpret as DNS name: #{arg.inspect}") end end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
:nodoc:
1227 1228 1229 1230 |
# File 'lib/resolv.rb', line 1227 def ==(other) # :nodoc: return false unless Name === other return @labels.join == other.to_a.join && @absolute == other.absolute? end |
#[](i) ⇒ Object
:nodoc:
1268 1269 1270 |
# File 'lib/resolv.rb', line 1268 def [](i) # :nodoc: return @labels[i] end |
#absolute? ⇒ Boolean
True if this name is absolute.
1223 1224 1225 |
# File 'lib/resolv.rb', line 1223 def absolute? return @absolute end |
#hash ⇒ Object
:nodoc:
1256 1257 1258 |
# File 'lib/resolv.rb', line 1256 def hash # :nodoc: return @labels.hash ^ @absolute.hash end |
#inspect ⇒ Object
:nodoc:
1216 1217 1218 |
# File 'lib/resolv.rb', line 1216 def inspect # :nodoc: "#<#{self.class}: #{self.to_s}#{@absolute ? '.' : ''}>" end |
#length ⇒ Object
:nodoc:
1264 1265 1266 |
# File 'lib/resolv.rb', line 1264 def length # :nodoc: return @labels.length end |
#subdomain_of?(other) ⇒ Boolean
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
1248 1249 1250 1251 1252 1253 1254 |
# File 'lib/resolv.rb', line 1248 def subdomain_of?(other) raise ArgumentError, "not a domain name: #{other.inspect}" unless Name === other return false if @absolute != other.absolute? other_len = other.length return false if @labels.length <= other_len return @labels[-other_len, other_len] == other.to_a end |
#to_a ⇒ Object
:nodoc:
1260 1261 1262 |
# File 'lib/resolv.rb', line 1260 def to_a # :nodoc: return @labels end |
#to_s ⇒ Object
1283 1284 1285 |
# File 'lib/resolv.rb', line 1283 def to_s return @labels.join('.') end |