Class: Resolv::LOC::Size
- Inherits:
-
Object
- Object
- Resolv::LOC::Size
- Defined in:
- lib/resolv.rb
Overview
A Resolv::LOC::Size
Constant Summary collapse
- Regex =
Regular expression LOC size must match.
/\A0*(\d{1,8}(?:\.\d+)?)m\z/
Instance Attribute Summary collapse
-
#scalar ⇒ Object
readonly
The raw size.
Class Method Summary collapse
-
.create(arg) ⇒ Object
Creates a new LOC::Size from
argwhich may be:.
Instance Method Summary collapse
-
#==(other) ⇒ Object
:nodoc:.
-
#eql?(other) ⇒ Boolean
:nodoc:.
-
#hash ⇒ Object
:nodoc:.
-
#initialize(scalar) ⇒ Size
constructor
Internal use; use self.create.
-
#inspect ⇒ Object
:nodoc:.
-
#to_s ⇒ Object
:nodoc:.
Constructor Details
#initialize(scalar) ⇒ Size
Internal use; use self.create.
3474 3475 3476 |
# File 'lib/resolv.rb', line 3474 def initialize(scalar) @scalar = scalar end |
Instance Attribute Details
#scalar ⇒ Object (readonly)
The raw size
3481 3482 3483 |
# File 'lib/resolv.rb', line 3481 def scalar @scalar end |
Class Method Details
.create(arg) ⇒ Object
Creates a new LOC::Size from arg which may be:
LOC::Size:: returns arg.
- String
argmust match the LOC::Size::Regex constant
3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 |
# File 'lib/resolv.rb', line 3455 def self.create(arg) case arg when Size return arg when String unless Regex =~ arg raise ArgumentError.new("not a properly formed Size string: " + arg) end unless (0.0...1e8) === (scalar = $1.to_f) raise ArgumentError.new("out of range as Size: #{arg}") end str = (scalar * 100).to_i.to_s return new([(str[0].to_i << 4) + (str.bytesize-1)].pack("C")) else raise ArgumentError.new("cannot interpret as Size: #{arg.inspect}") end end |
Instance Method Details
#==(other) ⇒ Object
:nodoc:
3492 3493 3494 |
# File 'lib/resolv.rb', line 3492 def ==(other) # :nodoc: return @scalar == other.scalar end |
#eql?(other) ⇒ Boolean
:nodoc:
3496 3497 3498 |
# File 'lib/resolv.rb', line 3496 def eql?(other) # :nodoc: return self == other end |
#hash ⇒ Object
:nodoc:
3500 3501 3502 |
# File 'lib/resolv.rb', line 3500 def hash # :nodoc: return @scalar.hash end |
#inspect ⇒ Object
:nodoc:
3488 3489 3490 |
# File 'lib/resolv.rb', line 3488 def inspect # :nodoc: return "#<#{self.class} #{self}>" end |
#to_s ⇒ Object
:nodoc:
3483 3484 3485 3486 |
# File 'lib/resolv.rb', line 3483 def to_s # :nodoc: s, = @scalar.unpack("C") return "#{(s >> 4) * (10.0 ** ((s & 0xf) - 2))}m" end |