Class: Resolv::LOC::Size

Inherits:
Object
  • Object
show all
Defined in:
lib/logstash/patches/resolv_9270.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.



2698
2699
2700
# File 'lib/logstash/patches/resolv_9270.rb', line 2698

def initialize(scalar)
  @scalar = scalar
end

Instance Attribute Details

#scalarObject (readonly)

The raw size



2705
2706
2707
# File 'lib/logstash/patches/resolv_9270.rb', line 2705

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



2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
# File 'lib/logstash/patches/resolv_9270.rb', line 2681

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:



2716
2717
2718
# File 'lib/logstash/patches/resolv_9270.rb', line 2716

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

#eql?(other) ⇒ Boolean

:nodoc:

Returns:

  • (Boolean)


2720
2721
2722
# File 'lib/logstash/patches/resolv_9270.rb', line 2720

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

#hashObject

:nodoc:



2724
2725
2726
# File 'lib/logstash/patches/resolv_9270.rb', line 2724

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

#inspectObject

:nodoc:



2712
2713
2714
# File 'lib/logstash/patches/resolv_9270.rb', line 2712

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

#to_sObject

:nodoc:



2707
2708
2709
2710
# File 'lib/logstash/patches/resolv_9270.rb', line 2707

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