Class: OoxmlParser::Note

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

Instance Attribute Summary collapse

Attributes inherited from OOXMLDocumentObject

#parent

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from OOXMLDocumentObject

#==, add_to_xmls_stack, copy_file_and_rename_to_zip, current_xml, dir, encrypted_file?, get_link_from_rels, unzip_file, #with_data?

Methods included from OoxmlDocumentObjectHelper

#to_hash

Constructor Details

#initializeNote

Returns a new instance of Note.



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

def initialize
  @elements = []
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(params) ⇒ 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
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/page_properties/note.rb', line 9

def self.parse(params)
  note = Note.new
  note.type = params[:type]
  note.assigned_to = params[:assigned_to]
  note.parent = params[:parent]
  doc = Nokogiri::XML(File.open(OOXMLDocumentObject.path_to_folder + "word/#{params[:target]}"))
  if note.type.include?('footer')
    xpath_note = '//w:ftr'
  elsif note.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 << params[:default_paragraph].dup.parse(sub_element, number, params[:default_character], parent: note)
        number += 1
      elsif sub_element.name == 'tbl'
        note.elements << Table.new(parent: note).parse(sub_element, number)
        number += 1
      elsif sub_element.name == 'std'
        sub_element.xpath('w:p').each do |p|
          note.elements << params[:default_paragraph].copy.parse(p, number, params[:default_character])
          number += 1
        end
        sub_element.xpath('w:sdtContent').each do |sdt_content|
          sdt_content.xpath('w:p').each do |p|
            note.elements << params[:default_paragraph].copy.parse(p, number, params[:default_character])
            number += 1
          end
        end
      end
    end
  end
  note
end