class OoxmlParser::HeaderFooter
Class Header Footer classes
Attributes
elements[R]
@return [Array<OOXMLDocumentObject>] list of elements if object
id[R]
@return [Integer] id of header-footer
path_suffix[R]
@return [String] suffix for object files
type[R]
@return [Symbol] ‘:header` or `:footer`
Public Class Methods
new(type = :header, parent: nil)
click to toggle source
Calls superclass method
OoxmlParser::OOXMLDocumentObject::new
# 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
Public Instance Methods
parse(node)
click to toggle source
Parse HeaderFooter
@param [Nokogiri::XML:Node] node with HeaderFooter
@return [HeaderFooter] result of parsing
# 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)
click to toggle source
Parse type and path suffix by node type @param [Nokogiri::XML:Node] node with HeaderFooter
# 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()
click to toggle source
@return [String] string with xml path
# 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()
click to toggle source
@return [String] string for search of xpath
# File lib/ooxml_parser/docx_parser/document_structure/header_footer.rb, line 22 def xpath_for_search "//w:#{path_suffix}" end