Class: OoxmlParser::HeaderFooter
- Inherits:
-
OOXMLDocumentObject
- Object
- OOXMLDocumentObject
- OoxmlParser::HeaderFooter
- Defined in:
- lib/ooxml_parser/docx_parser/document_structure/header_footer.rb
Overview
Class Header Footer classes
Instance Attribute Summary collapse
-
#elements ⇒ Array<OOXMLDocumentObject>
readonly
List of elements if object.
-
#id ⇒ Integer
readonly
Id of header-footer.
-
#path_suffix ⇒ String
readonly
Suffix for object files.
-
#type ⇒ Symbol
readonly
‘:header` or `:footer`.
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
#==, #boolean_attribute_value, #parse_xml, #with_data?
Methods included from OoxmlObjectAttributeHelper
#attribute_enabled?, #option_enabled?
Methods included from OoxmlDocumentObjectHelper
Constructor Details
#initialize(type = :header, parent: nil) ⇒ HeaderFooter
Returns a new instance of HeaderFooter.
15 16 17 18 19 |
# File 'lib/ooxml_parser/docx_parser/document_structure/header_footer.rb', line 15 def initialize(type = :header, parent: nil) @type = type @elements = [] super(parent: parent) end |
Instance Attribute Details
#elements ⇒ Array<OOXMLDocumentObject> (readonly)
Returns list of elements if object.
9 10 11 |
# File 'lib/ooxml_parser/docx_parser/document_structure/header_footer.rb', line 9 def elements @elements end |
#id ⇒ Integer (readonly)
Returns id of header-footer.
7 8 9 |
# File 'lib/ooxml_parser/docx_parser/document_structure/header_footer.rb', line 7 def id @id end |
#path_suffix ⇒ String (readonly)
Returns suffix for object files.
13 14 15 |
# File 'lib/ooxml_parser/docx_parser/document_structure/header_footer.rb', line 13 def path_suffix @path_suffix end |
#type ⇒ Symbol (readonly)
Returns ‘:header` or `:footer`.
11 12 13 |
# File 'lib/ooxml_parser/docx_parser/document_structure/header_footer.rb', line 11 def type @type end |
Instance Method Details
#parse(node) ⇒ HeaderFooter
Parse HeaderFooter
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/ooxml_parser/docx_parser/document_structure/header_footer.rb', line 47 def parse(node) node.attributes.each do |key, value| case key when 'id' @id = value.value.to_i end end parse_type(node) doc = parse_xml(root_object.unpacked_folder + xml_path) doc.search(xpath_for_search).each do |footnote| footnote_id = nil footnote.attributes.each do |key, value| case key when 'id' footnote_id = value.value.to_i end end next unless footnote_id == @id paragraph_number = 0 footnote.xpath('w:p').each do |paragraph| @elements << root_object.default_paragraph_style.dup.parse(paragraph, paragraph_number, root_object.default_run_style, parent: self) paragraph_number += 1 end end self end |
#parse_type(node) ⇒ Object
Parse type and path suffix by node type
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/ooxml_parser/docx_parser/document_structure/header_footer.rb', line 33 def parse_type(node) case node.name when 'footnoteReference' @path_suffix = 'footnote' @type = :header when 'endnoteReference' @path_suffix = 'endnote' @type = :footer end end |
#xml_path ⇒ String
Returns string with xml path.
27 28 29 |
# File 'lib/ooxml_parser/docx_parser/document_structure/header_footer.rb', line 27 def xml_path "word/#{path_suffix}s.xml" end |
#xpath_for_search ⇒ String
Returns string for search of xpath.
22 23 24 |
# File 'lib/ooxml_parser/docx_parser/document_structure/header_footer.rb', line 22 def xpath_for_search "//w:#{path_suffix}" end |