Sha256: b07296824fd18fc7959dab12c1a9a0b35f31971cc1a7073b500c3e82c42befde

Contents?: true

Size: 1.46 KB

Versions: 2

Compression:

Stored size: 1.46 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 = []
    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

2 entries across 2 versions & 1 rubygems

Version Path
ooxml_parser-0.8.1 lib/ooxml_parser/docx_parser/docx_data/document_structure/page_properties/note.rb
ooxml_parser-0.8.0 lib/ooxml_parser/docx_parser/docx_data/document_structure/page_properties/note.rb