Class: Gem::Resolv::LOC::Size

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

Overview

A Gem::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.



3250
3251
3252
# File 'lib/rubygems/vendor/resolv/lib/resolv.rb', line 3250

def initialize(scalar)
  @scalar = scalar
end

Instance Attribute Details

#scalarObject (readonly)

The raw size



3257
3258
3259
# File 'lib/rubygems/vendor/resolv/lib/resolv.rb', line 3257

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



3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
# File 'lib/rubygems/vendor/resolv/lib/resolv.rb', line 3233

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:



3268
3269
3270
# File 'lib/rubygems/vendor/resolv/lib/resolv.rb', line 3268

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

#eql?(other) ⇒ Boolean

:nodoc:

Returns:

  • (Boolean)


3272
3273
3274
# File 'lib/rubygems/vendor/resolv/lib/resolv.rb', line 3272

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

#hashObject

:nodoc:



3276
3277
3278
# File 'lib/rubygems/vendor/resolv/lib/resolv.rb', line 3276

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

#inspectObject

:nodoc:



3264
3265
3266
# File 'lib/rubygems/vendor/resolv/lib/resolv.rb', line 3264

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

#to_sObject

:nodoc:



3259
3260
3261
3262
# File 'lib/rubygems/vendor/resolv/lib/resolv.rb', line 3259

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