Class: UR::Serialize::DataObject
- Inherits:
-
Object
- Object
- UR::Serialize::DataObject
- Defined in:
- lib/serialize.rb
Instance Attribute Summary collapse
-
#recipe_id ⇒ Object
Returns the value of attribute recipe_id.
-
#values ⇒ Object
readonly
Returns the value of attribute values.
Class Method Summary collapse
Instance Method Summary collapse
- #[](item) ⇒ Object
- #[]=(item, value) ⇒ Object
-
#initialize ⇒ DataObject
constructor
A new instance of DataObject.
- #pack(names, types) ⇒ Object
Constructor Details
#initialize ⇒ DataObject
Returns a new instance of DataObject.
79 80 81 82 |
# File 'lib/serialize.rb', line 79 def initialize @values = {} @recipe_id = nil end |
Instance Attribute Details
#recipe_id ⇒ Object
Returns the value of attribute recipe_id.
77 78 79 |
# File 'lib/serialize.rb', line 77 def recipe_id @recipe_id end |
#values ⇒ Object (readonly)
Returns the value of attribute values.
76 77 78 |
# File 'lib/serialize.rb', line 76 def values @values end |
Class Method Details
.create_empty(names, recipe_id) ⇒ Object
114 115 116 117 118 119 120 121 |
# File 'lib/serialize.rb', line 114 def self.create_empty(names, recipe_id) obj = DataObject.new names.each do |i| obj.values[i] = nil end obj.recipe_id = recipe_id obj end |
.unpack(data, names, types) ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/serialize.rb', line 91 def self.unpack(data, names, types) if names.length != types.length raise RuntimeError.new('List sizes are not identical.') end obj = DataObject.new offset = 0 obj.recipe_id = data[0] #puts "Datat:" + data.to_s names.each_with_index do |name,i| #obj.values[i] = data[1..-1].unpack('x' * offset + types[i]) #puts unpack_field(data[1..-1], offset, types[i]) obj.values[name] = Serialize.unpack_field(data[1..-1], offset, types[i]) #puts "obj" #puts obj.values[i] offset += Serialize::get_item_size(types[i]) end #puts "obj:" + obj.values.to_s obj end |
Instance Method Details
#[](item) ⇒ Object
84 85 86 |
# File 'lib/serialize.rb', line 84 def [](item) @values[item] end |
#[]=(item, value) ⇒ Object
87 88 89 |
# File 'lib/serialize.rb', line 87 def []=(item,value) @values[item] = value end |
#pack(names, types) ⇒ Object
123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/serialize.rb', line 123 def pack(names, types) if names.length != types.length raise RuntimeError.new('List sizes are not identical.') end l = [] l.append @recipe_id if @recipe_id names.each do |i| raise RuntimeError.new('Uninitialized parameter: ' + i) unless @values[i] l.push *@values[i] end l end |