Class: Gem::Resolv::DNS::Name
- Inherits:
-
Object
- Object
- Gem::Resolv::DNS::Name
- Defined in:
- lib/rubygems/vendor/resolv/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:
1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 |
# File 'lib/rubygems/vendor/resolv/lib/resolv.rb', line 1297 def initialize(labels, absolute=true) # :nodoc: labels = labels.map {|label| case label when String then Label::Str.new(label) when Label::Str then label else raise ArgumentError, "unexpected label: #{label.inspect}" end } @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.
1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 |
# File 'lib/rubygems/vendor/resolv/lib/resolv.rb', line 1286 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:
1321 1322 1323 1324 1325 |
# File 'lib/rubygems/vendor/resolv/lib/resolv.rb', line 1321 def ==(other) # :nodoc: return false unless Name === other return false unless @absolute == other.absolute? return @labels == other.to_a end |
#[](i) ⇒ Object
:nodoc:
1363 1364 1365 |
# File 'lib/rubygems/vendor/resolv/lib/resolv.rb', line 1363 def [](i) # :nodoc: return @labels[i] end |
#absolute? ⇒ Boolean
True if this name is absolute.
1317 1318 1319 |
# File 'lib/rubygems/vendor/resolv/lib/resolv.rb', line 1317 def absolute? return @absolute end |
#hash ⇒ Object
:nodoc:
1351 1352 1353 |
# File 'lib/rubygems/vendor/resolv/lib/resolv.rb', line 1351 def hash # :nodoc: return @labels.hash ^ @absolute.hash end |
#inspect ⇒ Object
:nodoc:
1310 1311 1312 |
# File 'lib/rubygems/vendor/resolv/lib/resolv.rb', line 1310 def inspect # :nodoc: "#<#{self.class}: #{self}#{@absolute ? '.' : ''}>" end |
#length ⇒ Object
:nodoc:
1359 1360 1361 |
# File 'lib/rubygems/vendor/resolv/lib/resolv.rb', line 1359 def length # :nodoc: return @labels.length end |
#subdomain_of?(other) ⇒ Boolean
Returns true if other
is a subdomain.
Example:
domain = Gem::Resolv::DNS::Name.create("y.z")
p Gem::Resolv::DNS::Name.create("w.x.y.z").subdomain_of?(domain) #=> true
p Gem::Resolv::DNS::Name.create("x.y.z").subdomain_of?(domain) #=> true
p Gem::Resolv::DNS::Name.create("y.z").subdomain_of?(domain) #=> false
p Gem::Resolv::DNS::Name.create("z").subdomain_of?(domain) #=> false
p Gem::Resolv::DNS::Name.create("x.y.z.").subdomain_of?(domain) #=> false
p Gem::Resolv::DNS::Name.create("w.z").subdomain_of?(domain) #=> false
1343 1344 1345 1346 1347 1348 1349 |
# File 'lib/rubygems/vendor/resolv/lib/resolv.rb', line 1343 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:
1355 1356 1357 |
# File 'lib/rubygems/vendor/resolv/lib/resolv.rb', line 1355 def to_a # :nodoc: return @labels end |
#to_s ⇒ Object
1378 1379 1380 |
# File 'lib/rubygems/vendor/resolv/lib/resolv.rb', line 1378 def to_s return @labels.join('.') end |