Class: DMAP::MeasuredInteger
- Inherits:
-
Object
- Object
- DMAP::MeasuredInteger
- Defined in:
- lib/dmap.rb
Overview
Allows people to specify a integer and the size of the binary representation required
If you create one with a wanted_box_size that’s not 1,2,4,8 you’ll run into trouble elsewhere (most likely)
Instance Attribute Summary collapse
-
#binary ⇒ Object
Returns the value of attribute binary.
-
#box_size ⇒ Object
Returns the value of attribute box_size.
-
#signed ⇒ Object
Returns the value of attribute signed.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
-
#initialize(value, box_size = 1, signed = false) ⇒ MeasuredInteger
constructor
A new instance of MeasuredInteger.
- #inspect ⇒ Object
- #pack_code ⇒ Object
-
#to_dmap ⇒ Object
TODO: Tidy me.
Constructor Details
#initialize(value, box_size = 1, signed = false) ⇒ MeasuredInteger
Returns a new instance of MeasuredInteger.
240 241 242 243 244 |
# File 'lib/dmap.rb', line 240 def initialize(value,box_size = 1,signed = false) @value = value.to_i @box_size = box_size @signed = signed end |
Instance Attribute Details
#binary ⇒ Object
Returns the value of attribute binary.
238 239 240 |
# File 'lib/dmap.rb', line 238 def binary @binary end |
#box_size ⇒ Object
Returns the value of attribute box_size.
238 239 240 |
# File 'lib/dmap.rb', line 238 def box_size @box_size end |
#signed ⇒ Object
Returns the value of attribute signed.
238 239 240 |
# File 'lib/dmap.rb', line 238 def signed @signed end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
237 238 239 |
# File 'lib/dmap.rb', line 237 def value @value end |
Instance Method Details
#inspect ⇒ Object
259 260 261 |
# File 'lib/dmap.rb', line 259 def inspect @value end |
#pack_code ⇒ Object
255 256 257 |
# File 'lib/dmap.rb', line 255 def pack_code {1=>"C",-1=>"c",2=>"n",4=>"N",8=>"Q",-8=>"q"}[@box_size * (@signed ? -1 : 1)] # FIXME: pack codes for all signed cases end |
#to_dmap ⇒ Object
TODO: Tidy me
246 247 248 249 250 251 252 253 |
# File 'lib/dmap.rb', line 246 def to_dmap # TODO: Tidy me case @box_size when 1,2,4,8 [@box_size,@value].pack("N"<<pack_code) else raise "I don't know how to unpack an integer #{@box_size} bytes long" end end |