Sha256: 2fad71ee5c1b92bba2d5bb13efcce3403d6fadf99b0210dbefc6182bf28f29fd

Contents?: true

Size: 1.49 KB

Versions: 28

Compression:

Stored size: 1.49 KB

Contents

# frozen_string_literal: true

module OoxmlParser
  # Class with data of Note
  class Note < OOXMLDocumentObject
    attr_accessor :type, :elements, :assigned_to

    def initialize
      @elements = []
      super(parent: nil)
    end

    # Parse note data
    # @param params [Hash] data to parse
    # @return [Note] result of parsing
    def self.parse(params)
      note = Note.new
      note.type = params[:type]
      note.assigned_to = params[:assigned_to]
      note.parent = params[:parent]
      doc = note.parse_xml(note.file_path(params[:target]))
      if note.type.include?('footer')
        xpath_note = '//w:ftr'
      elsif note.type.include?('header')
        xpath_note = '//w:hdr'
      end
      doc.search(xpath_note).each do |ftr|
        number = 0
        ftr.xpath('*').each do |sub_element|
          case sub_element.name
          when 'p'
            note.elements << params[:default_paragraph].dup.parse(sub_element, number, params[:default_character], parent: note)
            number += 1
          when 'tbl'
            note.elements << Table.new(parent: note).parse(sub_element, number)
            number += 1
          end
        end
      end
      note
    end

    # @param target [String] name of target
    # @return [String] path to note xml file
    def file_path(target)
      file = "#{OOXMLDocumentObject.path_to_folder}word/#{target}"
      return file if File.exist?(file)

      "#{OOXMLDocumentObject.path_to_folder}#{target}" unless File.exist?(file)
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
ooxml_parser-0.29.0 lib/ooxml_parser/docx_parser/document_structure/page_properties/note.rb
ooxml_parser-0.28.0 lib/ooxml_parser/docx_parser/document_structure/page_properties/note.rb
ooxml_parser-0.27.0 lib/ooxml_parser/docx_parser/document_structure/page_properties/note.rb
ooxml_parser-0.26.0 lib/ooxml_parser/docx_parser/document_structure/page_properties/note.rb
ooxml_parser-0.25.0 lib/ooxml_parser/docx_parser/document_structure/page_properties/note.rb
ooxml_parser-0.24.0 lib/ooxml_parser/docx_parser/document_structure/page_properties/note.rb
ooxml_parser-0.23.0 lib/ooxml_parser/docx_parser/docx_data/document_structure/page_properties/note.rb
ooxml_parser-0.22.0 lib/ooxml_parser/docx_parser/docx_data/document_structure/page_properties/note.rb
ooxml_parser-0.21.0 lib/ooxml_parser/docx_parser/docx_data/document_structure/page_properties/note.rb
ooxml_parser-0.20.0 lib/ooxml_parser/docx_parser/docx_data/document_structure/page_properties/note.rb
ooxml_parser-0.19.0 lib/ooxml_parser/docx_parser/docx_data/document_structure/page_properties/note.rb
ooxml_parser-0.18.1 lib/ooxml_parser/docx_parser/docx_data/document_structure/page_properties/note.rb
ooxml_parser-0.18.0 lib/ooxml_parser/docx_parser/docx_data/document_structure/page_properties/note.rb
ooxml_parser-0.17.0 lib/ooxml_parser/docx_parser/docx_data/document_structure/page_properties/note.rb
ooxml_parser-0.16.0 lib/ooxml_parser/docx_parser/docx_data/document_structure/page_properties/note.rb
ooxml_parser-0.15.0 lib/ooxml_parser/docx_parser/docx_data/document_structure/page_properties/note.rb
ooxml_parser-0.14.2 lib/ooxml_parser/docx_parser/docx_data/document_structure/page_properties/note.rb
ooxml_parser-0.14.1-mingw32 lib/ooxml_parser/docx_parser/docx_data/document_structure/page_properties/note.rb
ooxml_parser-0.14.1 lib/ooxml_parser/docx_parser/docx_data/document_structure/page_properties/note.rb
ooxml_parser-0.14.0 lib/ooxml_parser/docx_parser/docx_data/document_structure/page_properties/note.rb