Class: Blender3d::FileBlock

Inherits:
Object
  • Object
show all
Includes:
Serializer
Defined in:
lib/blender-3d/file_block.rb

Defined Under Namespace

Classes: Reader

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(reader = nil) ⇒ FileBlock

Returns a new instance of FileBlock.



7
8
9
# File 'lib/blender-3d/file_block.rb', line 7

def initialize(reader = nil)
  deserialize(reader) if reader
end

Instance Attribute Details

#codeObject

Returns the value of attribute code.



5
6
7
# File 'lib/blender-3d/file_block.rb', line 5

def code
  @code
end

#countObject

Returns the value of attribute count.



5
6
7
# File 'lib/blender-3d/file_block.rb', line 5

def count
  @count
end

#dataObject

Returns the value of attribute data.



5
6
7
# File 'lib/blender-3d/file_block.rb', line 5

def data
  @data
end

#pointerObject

Returns the value of attribute pointer.



5
6
7
# File 'lib/blender-3d/file_block.rb', line 5

def pointer
  @pointer
end

#sizeObject

Returns the value of attribute size.



5
6
7
# File 'lib/blender-3d/file_block.rb', line 5

def size
  @size
end

#typeObject

Returns the value of attribute type.



5
6
7
# File 'lib/blender-3d/file_block.rb', line 5

def type
  @type
end

#type_indexObject

Returns the value of attribute type_index.



5
6
7
# File 'lib/blender-3d/file_block.rb', line 5

def type_index
  @type_index
end

Instance Method Details

#deserialize(reader) ⇒ Object



11
12
13
# File 'lib/blender-3d/file_block.rb', line 11

def deserialize(reader)
  Reader.new(reader, self).read
end

#parse_data(model) ⇒ Object



15
16
17
18
19
# File 'lib/blender-3d/file_block.rb', line 15

def parse_data(model)
  file = StringIO.new(data)
  reader = model.create_reader(file)
  self.data = count.times.map { self.type.read(reader) }
end

#to_xmlObject



21
22
23
24
25
26
27
28
29
# File 'lib/blender-3d/file_block.rb', line 21

def to_xml
  REXML::Element.new(self.class.basename).tap do |e|
    e.add_attribute 'code', code
    e.add_attribute 'pointer', pointer.inspect
    e.add_attribute 'size', size.to_s
    e.add_attribute 'type_index', type_index.to_s
    e.add_element data_to_xml
  end
end