Class: Resolv::LOC::Size

Inherits:
Object
  • Object
show all
Defined in:
lib/resolv.rb

Overview

A Resolv::LOC::Size

Constant Summary collapse

Regex =
/^(\d+\.*\d*)[m]$/

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(scalar) ⇒ Size

Returns a new instance of Size.



2632
2633
2634
# File 'lib/resolv.rb', line 2632

def initialize(scalar)
  @scalar = scalar
end

Instance Attribute Details

#scalarObject (readonly)

The raw size



2639
2640
2641
# File 'lib/resolv.rb', line 2639

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



2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
# File 'lib/resolv.rb', line 2615

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:



2650
2651
2652
# File 'lib/resolv.rb', line 2650

def ==(other) # :nodoc:
  return @scalar == other.scalar
end

#eql?(other) ⇒ Boolean

:nodoc:

Returns:

  • (Boolean)


2654
2655
2656
# File 'lib/resolv.rb', line 2654

def eql?(other) # :nodoc:
  return self == other
end

#hashObject

:nodoc:



2658
2659
2660
# File 'lib/resolv.rb', line 2658

def hash # :nodoc:
  return @scalar.hash
end

#inspectObject

:nodoc:



2646
2647
2648
# File 'lib/resolv.rb', line 2646

def inspect # :nodoc:
  return "#<#{self.class} #{self}>"
end

#to_sObject

:nodoc:



2641
2642
2643
2644
# File 'lib/resolv.rb', line 2641

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