Class: Arpie::BitBinaryType

Inherits:
BinaryType show all
Defined in:
lib/arpie/binary/pack_type.rb

Constant Summary

Constants included from Arpie

MTU, VERSION

Instance Method Summary collapse

Methods inherited from BinaryType

#binary_size, #check_limit, #required_opts

Methods included from Arpie

#bogon!, #incomplete!

Instance Method Details

#from(binary, opts) ⇒ Object



101
102
103
104
105
106
107
108
109
110
# File 'lib/arpie/binary/pack_type.rb', line 101

def from binary, opts
  len = opts[:length] || 1
  len = binary.size if len == :all
  binary.size >= len or incomplete!
  b = binary.split("")[0,len].map {|x|
    x == "1"
  }
  b = b[0] if b.size == 1
  [b, len]
end

#to(object, opts) ⇒ Object



112
113
114
115
# File 'lib/arpie/binary/pack_type.rb', line 112

def to object, opts
  object = [object] if object.is_a?(TrueClass) || object.is_a?(FalseClass)
  object.map {|x| x == true ? "1" : "0" }.join("")
end