Class: Resolv::LOC::Size

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

Overview

A Resolv::LOC::Size

Constant Summary collapse

Regex =

Regular expression LOC size must match.

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(scalar) ⇒ Size

Internal use; use self.create.



3376
3377
3378
# File 'lib/resolv.rb', line 3376

def initialize(scalar)
  @scalar = scalar
end

Instance Attribute Details

#scalarObject (readonly)

The raw size



3383
3384
3385
# File 'lib/resolv.rb', line 3383

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



3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
# File 'lib/resolv.rb', line 3358

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:



3394
3395
3396
# File 'lib/resolv.rb', line 3394

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

#eql?(other) ⇒ Boolean

:nodoc:

Returns:

  • (Boolean)


3398
3399
3400
# File 'lib/resolv.rb', line 3398

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

#hashObject

:nodoc:



3402
3403
3404
# File 'lib/resolv.rb', line 3402

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

#inspectObject

:nodoc:



3390
3391
3392
# File 'lib/resolv.rb', line 3390

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

#to_sObject

:nodoc:



3385
3386
3387
3388
# File 'lib/resolv.rb', line 3385

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