123456789_123456789_123456789_123456789_123456789_

Class: Resolv::LOC::Size

Do not use. This class is for internal use only.
Relationships & Source Files
Inherits: Object
Defined in: lib/resolv.rb

Overview

A Size

Constant Summary

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(scalar) ⇒ Size

Internal use; use self.create.

[ GitHub ]

  
# File 'lib/resolv.rb', line 3298

def initialize(scalar)
  @scalar = scalar
end

Class Method Details

.create(arg)

Creates a new Size from arg which may be:

LOC::Size:: returns arg.

String

arg must match the Regex constant

[ GitHub ]

  
# File 'lib/resolv.rb', line 3279

def self.create(arg)
  case arg
  when Size
    return arg
  when String
    unless Regex =~ arg
      raise ArgumentError.new("not a properly formed Size string: " + arg)
    end
    unless (0.0...1e8) === (scalar = $1.to_f)
      raise ArgumentError.new("out of range as Size: #{arg}")
    end
    str = (scalar * 100).to_i.to_s
    return new([(str[0].to_i << 4) + (str.bytesize-1)].pack("C"))
  else
    raise ArgumentError.new("cannot interpret as Size: #{arg.inspect}")
  end
end

Instance Attribute Details

#scalar (readonly)

The raw size

[ GitHub ]

  
# File 'lib/resolv.rb', line 3305

attr_reader :scalar

Instance Method Details

#==(other)

[ GitHub ]

  
# File 'lib/resolv.rb', line 3316

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

#eql?(other) ⇒ Boolean

[ GitHub ]

  
# File 'lib/resolv.rb', line 3320

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

#hash

[ GitHub ]

  
# File 'lib/resolv.rb', line 3324

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

#inspect

[ GitHub ]

  
# File 'lib/resolv.rb', line 3312

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

#to_s

[ GitHub ]

  
# File 'lib/resolv.rb', line 3307

def to_s # :nodoc:
  s, = @scalar.unpack("C")
  return "#{(s >> 4) * (10.0 ** ((s & 0xf) - 2))}m"
end