Class: OoxmlParser::Note

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

Constant Summary

Constants inherited from OOXMLDocumentObject

OOXMLDocumentObject::DEFAULT_DIRECTORY_FOR_MEDIA

Instance Attribute Summary collapse

Class Method 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 = nil, elements = [], assigned_to = nil) ⇒ Note

Returns a new instance of Note.



5
6
7
8
9
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/page_properties/note.rb', line 5

def initialize(type = nil, elements = [], assigned_to = nil)
  @type = type
  @elements = elements
  @assigned_to = assigned_to
end

Instance Attribute Details

#assigned_toObject

Returns the value of attribute assigned_to.



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

def assigned_to
  @assigned_to
end

#elementsObject

Returns the value of attribute elements.



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

def elements
  @elements
end

#typeObject

Returns the value of attribute type.



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

def type
  @type
end

Class Method Details

.parse(default_paragraph, default_character, target, assigned_to, type) ⇒ Object



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
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/page_properties/note.rb', line 11

def self.parse(default_paragraph, default_character, target, assigned_to, type)
  note = Note.new
  note.type = type
  note.assigned_to = assigned_to
  doc = Nokogiri::XML(File.open(OOXMLDocumentObject.path_to_folder + "word/#{target}"))
  if type.include?('footer')
    xpath_note = '//w:ftr'
  elsif type.include?('header')
    xpath_note = '//w:hdr'
  else
    raise "Cannot parse unknown Note type: #{type}"
  end
  doc.search(xpath_note).each do |ftr|
    number = 0
    ftr.xpath('*').each do |sub_element|
      if sub_element.name == 'p'
        note.elements << DocxParagraph.parse(sub_element, number, default_paragraph, default_character)
        number += 1
      elsif sub_element.name == 'tbl'
        note.elements << Table.parse(sub_element, number)
        number += 1
      elsif sub_element.name == 'std'
        sub_element.xpath('w:p').each do |p|
          note.elements << DocxParagraph.parse(p, number, default_paragraph, default_character)
          number += 1
        end
        sub_element.xpath('w:sdtContent').each do |sdt_content|
          sdt_content.xpath('w:p').each do |p|
            note.elements << DocxParagraph.parse(p, number, default_paragraph, default_character)
            number += 1
          end
        end
      end
    end
  end
  note
end