Class: OoxmlParser::HeaderFooter
- Inherits:
-
OOXMLDocumentObject
- Object
- OOXMLDocumentObject
- OoxmlParser::HeaderFooter
- Defined in:
- lib/ooxml_parser/docx_parser/docx_data/document_structure/header_footer.rb
Overview
Class Header Footer classes
Instance Attribute Summary collapse
-
#elements ⇒ Object
Returns the value of attribute elements.
-
#id ⇒ Object
Returns the value of attribute id.
-
#path_suffix ⇒ Object
Returns the value of attribute path_suffix.
-
#type ⇒ Object
Returns the value of attribute type.
Attributes inherited from OOXMLDocumentObject
Instance Method Summary collapse
-
#initialize(type = :header, parent: nil) ⇒ HeaderFooter
constructor
A new instance of HeaderFooter.
-
#parse(node) ⇒ HeaderFooter
Parse HeaderFooter.
-
#parse_type(node) ⇒ Object
Parse type and path suffix by node type.
-
#xml_path ⇒ String
String with xml path.
-
#xpath_for_search ⇒ String
String for search of xpath.
Methods inherited from OOXMLDocumentObject
#==, add_to_xmls_stack, copy_file_and_rename_to_zip, current_xml, dir, encrypted_file?, get_link_from_rels, unzip_file, #with_data?
Methods included from OoxmlDocumentObjectHelper
Constructor Details
#initialize(type = :header, parent: nil) ⇒ HeaderFooter
Returns a new instance of HeaderFooter.
7 8 9 10 11 |
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/header_footer.rb', line 7 def initialize(type = :header, parent: nil) @type = type @elements = [] @parent = parent end |
Instance Attribute Details
#elements ⇒ Object
Returns the value of attribute elements.
4 5 6 |
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/header_footer.rb', line 4 def elements @elements end |
#id ⇒ Object
Returns the value of attribute id.
4 5 6 |
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/header_footer.rb', line 4 def id @id end |
#path_suffix ⇒ Object
Returns the value of attribute path_suffix.
5 6 7 |
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/header_footer.rb', line 5 def path_suffix @path_suffix end |
#type ⇒ Object
Returns the value of attribute type.
4 5 6 |
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/header_footer.rb', line 4 def type @type end |
Instance Method Details
#parse(node) ⇒ HeaderFooter
Parse HeaderFooter
41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/header_footer.rb', line 41 def parse(node) @id = node.attribute('id').value.to_i parse_type(node) doc = Nokogiri::XML(File.open(OOXMLDocumentObject.path_to_folder + xml_path)) doc.search(xpath_for_search).each do |footnote| next unless footnote.attribute('id').value.to_i == @id paragraph_number = 0 footnote.xpath('w:p').each do |paragraph| @elements << DocumentStructure.default_paragraph_style.dup.parse(paragraph, paragraph_number, DocumentStructure.default_run_style, parent: self) paragraph_number += 1 end end self end |
#parse_type(node) ⇒ Object
Parse type and path suffix by node type
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/header_footer.rb', line 25 def parse_type(node) case node.name when 'footnoteReference' @path_suffix = 'footnote' @type = :header when 'endnoteReference' @path_suffix = 'endnote' @type = :footer else warn "Unknown HeaderFooter type: #{node.name}" end end |
#xml_path ⇒ String
Returns string with xml path.
19 20 21 |
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/header_footer.rb', line 19 def xml_path "word/#{path_suffix}s.xml" end |
#xpath_for_search ⇒ String
Returns string for search of xpath.
14 15 16 |
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/header_footer.rb', line 14 def xpath_for_search "//w:#{path_suffix}" end |