Class: Rocx::Parts::Document

Inherits:
BasePart show all
Defined in:
lib/rocx/parts/document.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from BasePart

#build_standalone_xml, #build_xml, #read

Constructor Details

#initializeDocument



6
7
8
# File 'lib/rocx/parts/document.rb', line 6

def initialize
  @children = []
end

Instance Attribute Details

#childrenObject (readonly)

Returns the value of attribute children.



4
5
6
# File 'lib/rocx/parts/document.rb', line 4

def children
  @children
end

#current_sectionObject (readonly)

Returns the value of attribute current_section.



4
5
6
# File 'lib/rocx/parts/document.rb', line 4

def current_section
  @current_section
end

Instance Method Details

#<<(child) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/rocx/parts/document.rb', line 10

def <<(child)
  if child.is_a?(Rocx::Section)
    set_section(child)
  else
    children << child
  end
end

#set_section(section) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/rocx/parts/document.rb', line 18

def set_section(section)
  if current_section.nil?
    @current_section = section
  else
    children.last.section_properties = current_section
    @current_section = section
  end
end

#to_xmlObject



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/rocx/parts/document.rb', line 27

def to_xml
  build_xml do |xml|
    xml.document(root_namespaces) {
      xml.parent.namespace = xml.parent.namespace_definitions.find { |ns| ns.prefix == "w" }
      xml["w"].body {
        children.each { |child| child.to_xml(xml) }
        current_section.to_xml(xml) unless current_section.nil?
      }
    }
  end
end