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.
2678 2679 2680 |
# File 'lib/resolv.rb', line 2678 def initialize(scalar) @scalar = scalar end |
Instance Attribute Details
#scalar ⇒ Object (readonly)
The raw size
2685 2686 2687 |
# File 'lib/resolv.rb', line 2685 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
2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 |
# File 'lib/resolv.rb', line 2661 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:
2696 2697 2698 |
# File 'lib/resolv.rb', line 2696 def ==(other) # :nodoc: return @scalar == other.scalar end |
#eql?(other) ⇒ Boolean
:nodoc:
2700 2701 2702 |
# File 'lib/resolv.rb', line 2700 def eql?(other) # :nodoc: return self == other end |
#hash ⇒ Object
:nodoc:
2704 2705 2706 |
# File 'lib/resolv.rb', line 2704 def hash # :nodoc: return @scalar.hash end |
#inspect ⇒ Object
:nodoc:
2692 2693 2694 |
# File 'lib/resolv.rb', line 2692 def inspect # :nodoc: return "#<#{self.class} #{self}>" end |
#to_s ⇒ Object
:nodoc:
2687 2688 2689 2690 |
# File 'lib/resolv.rb', line 2687 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 |