Class: OpenXml::Docx::Parts::Document
- Inherits:
-
Part
- Object
- Part
- OpenXml::Docx::Parts::Document
- Defined in:
- lib/openxml/docx/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
Constructor Details
#initialize ⇒ Document
Returns a new instance of Document.
7 8 9 |
# File 'lib/openxml/docx/parts/document.rb', line 7 def initialize @children = [] end |
Instance Attribute Details
#children ⇒ Object (readonly)
Returns the value of attribute children.
5 6 7 |
# File 'lib/openxml/docx/parts/document.rb', line 5 def children @children end |
#current_section ⇒ Object (readonly)
Returns the value of attribute current_section.
5 6 7 |
# File 'lib/openxml/docx/parts/document.rb', line 5 def current_section @current_section end |
Instance Method Details
#<<(child) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/openxml/docx/parts/document.rb', line 11 def <<(child) if child.is_a?(OpenXml::Docx::Section) set_section(child) else children << child end end |
#set_section(section) ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/openxml/docx/parts/document.rb', line 19 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
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/openxml/docx/parts/document.rb', line 28 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 |