Class: ArrayOfSubclasses

Inherits:
BinData::Primitive
  • Object
show all
Defined in:
lib/helpers/array_of_subclasses.rb

Direct Known Subclasses

OFActions, OFQueueProperties

Instance Method Summary collapse

Instance Method Details

#getObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/helpers/array_of_subclasses.rb', line 8

def get
  items = []
  tmp = binary
  until tmp.empty?
    type_index = BinData::Uint16be.read(tmp)
    type_str = types.fetch(type_index)
    class_name = name + type_str.to_s.split('_').map(&:capitalize).join
    klass = Object.const_get class_name
    item = klass.read(tmp)
    items << item
    tmp = tmp[item.len..-1]
  end
  items
end

#set(value) ⇒ Object



23
24
25
# File 'lib/helpers/array_of_subclasses.rb', line 23

def set(value)
  self.binary = value.map(&:to_binary_s).join
end