Class: Resolv::LOC::Size
- Inherits:
-
Object
- Object
- Resolv::LOC::Size
- Defined in:
- lib/resolv.rb
Overview
A Resolv::LOC::Size
Constant Summary collapse
- Regex =
/^(\d+\.*\d*)[m]$/
Instance Attribute Summary collapse
-
#scalar ⇒ Object
readonly
The raw size.
Class Method Summary collapse
-
.create(arg) ⇒ Object
Creates a new LOC::Size from
arg
which may be:.
Instance Method Summary collapse
-
#==(other) ⇒ Object
:nodoc:.
-
#eql?(other) ⇒ Boolean
:nodoc:.
-
#hash ⇒ Object
:nodoc:.
-
#initialize(scalar) ⇒ Size
constructor
A new instance of Size.
-
#inspect ⇒ Object
:nodoc:.
-
#to_s ⇒ Object
:nodoc:.
Constructor Details
#initialize(scalar) ⇒ Size
Returns a new instance of Size.
2651 2652 2653 |
# File 'lib/resolv.rb', line 2651 def initialize(scalar) @scalar = scalar end |
Instance Attribute Details
#scalar ⇒ Object (readonly)
The raw size
2658 2659 2660 |
# File 'lib/resolv.rb', line 2658 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
-
arg
must match the LOC::Size::Regex constant
2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 |
# File 'lib/resolv.rb', line 2634 def self.create(arg) case arg when Size return arg when String scalar = '' if Regex =~ arg scalar = [(($1.to_f*(1e2)).to_i.to_s[0].to_i*(2**4)+(($1.to_f*(1e2)).to_i.to_s.length-1))].pack("C") else raise ArgumentError.new("not a properly formed Size string: " + arg) end return Size.new(scalar) else raise ArgumentError.new("cannot interpret as Size: #{arg.inspect}") end end |
Instance Method Details
#==(other) ⇒ Object
:nodoc:
2669 2670 2671 |
# File 'lib/resolv.rb', line 2669 def ==(other) # :nodoc: return @scalar == other.scalar end |
#eql?(other) ⇒ Boolean
:nodoc:
2673 2674 2675 |
# File 'lib/resolv.rb', line 2673 def eql?(other) # :nodoc: return self == other end |
#hash ⇒ Object
:nodoc:
2677 2678 2679 |
# File 'lib/resolv.rb', line 2677 def hash # :nodoc: return @scalar.hash end |
#inspect ⇒ Object
:nodoc:
2665 2666 2667 |
# File 'lib/resolv.rb', line 2665 def inspect # :nodoc: return "#<#{self.class} #{self}>" end |
#to_s ⇒ Object
:nodoc:
2660 2661 2662 2663 |
# File 'lib/resolv.rb', line 2660 def to_s # :nodoc: s = @scalar.unpack("H2").join.to_s return ((s[0].to_i)*(10**(s[1].to_i-2))).to_s << "m" end |