Class: Blender3d::Structure
- Inherits:
-
Object
- Object
- Blender3d::Structure
- Includes:
- Serializer
- Defined in:
- lib/blender-3d/structure.rb
Class Attribute Summary collapse
-
.definition ⇒ Object
readonly
Returns the value of attribute definition.
Instance Method Summary collapse
- #deserialize(reader) ⇒ Object
-
#initialize(reader = nil) ⇒ Structure
constructor
A new instance of Structure.
- #to_xml ⇒ Object
Constructor Details
#initialize(reader = nil) ⇒ Structure
Returns a new instance of Structure.
9 10 11 |
# File 'lib/blender-3d/structure.rb', line 9 def initialize(reader = nil) deserialize(reader) if reader end |
Class Attribute Details
.definition ⇒ Object (readonly)
Returns the value of attribute definition.
4 5 6 |
# File 'lib/blender-3d/structure.rb', line 4 def definition @definition end |
Instance Method Details
#deserialize(reader) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/blender-3d/structure.rb', line 13 def deserialize(reader) self.class.definition.fields.each do |field| value = field.type.read(reader) instance_variable_set "@#{field.name}", value end self end |
#to_xml ⇒ Object
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/blender-3d/structure.rb', line 21 def to_xml vars = instance_variables.map do |n| value = instance_variable_get(n) REXML::Element.new(n[1..-1]).tap { |e| e << value_to_xml(value) } end REXML::Element.new(self.class.basename).tap do |e| vars.each { |v| e.add_element v } end end |