class Blender3d::Structure

Attributes

definition[R]

Public Class Methods

new(reader = nil) click to toggle source
# File lib/blender-3d/structure.rb, line 9
def initialize(reader = nil)
  deserialize(reader) if reader
end

Public Instance Methods

deserialize(reader) click to toggle source
# 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() click to toggle source
# 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