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.



2615
2616
2617
# File 'lib/resolv.rb', line 2615

def initialize(scalar)
  @scalar = scalar
end

Instance Attribute Details

#scalarObject (readonly)

The raw size



2622
2623
2624
# File 'lib/resolv.rb', line 2622

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



2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
# File 'lib/resolv.rb', line 2598

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:



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

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

#eql?(other) ⇒ Boolean

:nodoc:

Returns:

  • (Boolean)


2637
2638
2639
# File 'lib/resolv.rb', line 2637

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

#hashObject

:nodoc:



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

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

#inspectObject

:nodoc:



2629
2630
2631
# File 'lib/resolv.rb', line 2629

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

#to_sObject

:nodoc:



2624
2625
2626
2627
# File 'lib/resolv.rb', line 2624

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