Sha256: d8dace7a7fecbc57dd4845431e430f89d732f32434d88f2bb0caa1c8f86ae786
Contents?: true
Size: 1.61 KB
Versions: 1
Compression:
Stored size: 1.61 KB
Contents
module OoxmlParser # Class Header Footer classes class HeaderFooter < OOXMLDocumentObject attr_accessor :id, :elements, :type attr_accessor :path_suffix def initialize(type = :header, parent: nil) @type = type @elements = [] @parent = parent end # @return [String] string for search of xpath def xpath_for_search "//w:#{path_suffix}" end # @return [String] string with xml path def xml_path "word/#{path_suffix}s.xml" end # Parse type and path suffix by node type # @param [Nokogiri::XML:Node] node with HeaderFooter 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 # Parse HeaderFooter # @param [Nokogiri::XML:Node] node with HeaderFooter # @return [HeaderFooter] result of parsing 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.copy.parse(paragraph, paragraph_number, DocumentStructure.default_run_style, parent: self) paragraph_number += 1 end end self end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
ooxml_parser-0.2.0 | lib/ooxml_parser/docx_parser/docx_data/document_structure/header_footer.rb |