Class: Rocx::Parts::Document
- Defined in:
- lib/rocx/parts/document.rb
Instance Attribute Summary collapse
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#current_section ⇒ Object
readonly
Returns the value of attribute current_section.
Instance Method Summary collapse
- #<<(child) ⇒ Object
-
#initialize ⇒ Document
constructor
A new instance of Document.
- #set_section(section) ⇒ Object
- #to_xml ⇒ Object
Methods inherited from BasePart
#build_standalone_xml, #build_xml, #read
Constructor Details
#initialize ⇒ Document
6 7 8 |
# File 'lib/rocx/parts/document.rb', line 6 def initialize @children = [] end |
Instance Attribute Details
#children ⇒ Object (readonly)
Returns the value of attribute children.
4 5 6 |
# File 'lib/rocx/parts/document.rb', line 4 def children @children end |
#current_section ⇒ Object (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_xml ⇒ Object
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 |