Class: OoxmlParser::HeaderFooter

Inherits:
OOXMLDocumentObject show all
Defined in:
lib/ooxml_parser/docx_parser/docx_data/document_structure/header_footer.rb

Constant Summary

Constants inherited from OOXMLDocumentObject

OOXMLDocumentObject::DEFAULT_DIRECTORY_FOR_MEDIA

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from OOXMLDocumentObject

#==, add_to_xmls_stack, copy_file_and_rename_to_zip, copy_media_file, current_xml, dir, encrypted_file?, get_link_from_rels, media_folder, option_enabled?, unzip_file

Constructor Details

#initialize(type = :header) ⇒ HeaderFooter

Returns a new instance of HeaderFooter.



5
6
7
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/header_footer.rb', line 5

def initialize(type = :header)
  @type = type
end

Instance Attribute Details

#descriptionObject

Returns the value of attribute description.



3
4
5
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/header_footer.rb', line 3

def description
  @description
end

#idObject

Returns the value of attribute id.



3
4
5
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/header_footer.rb', line 3

def id
  @id
end

#typeObject

Returns the value of attribute type.



3
4
5
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/header_footer.rb', line 3

def type
  @type
end

Instance Method Details

#parse(type, id, default_paragraph, default_character) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/header_footer.rb', line 9

def parse(type, id, default_paragraph, default_character)
  if type == :header
    doc = Nokogiri::XML(File.open(OOXMLDocumentObject.path_to_folder + 'word/footnotes.xml'))
    doc.search('//w:footnote').each do |footnote|
      next unless footnote.attribute('id').value == id
      description = []
      paragraph_number = 0
      footnote.xpath('w:p').each do |paragraph|
        description << DocxParagraph.parse(paragraph, paragraph_number, default_paragraph, default_character)
        paragraph_number += 1
      end
      return description
    end
  elsif type == :header
    doc = Nokogiri::XML(File.open(OOXMLDocumentObject.path_to_folder + 'word/endnotes.xml'))
    doc.search('//w:endnote').each do |footnote|
      next unless footnote.attribute('id').value == id
      description = []
      paragraph_number = 0
      footnote.xpath('w:p').each do |paragraph|
        description << DocxParagraph.parse(paragraph, paragraph_number, default_paragraph, default_character)
        paragraph_number += 1
      end
      return description
    end
  end
end