class OoxmlParser::Note

Class with data of Note

Attributes

assigned_to[RW]
elements[RW]
type[RW]

Public Class Methods

new(type: 'unknown') click to toggle source
Calls superclass method OoxmlParser::OOXMLDocumentObject::new
# File lib/ooxml_parser/docx_parser/document_structure/page_properties/note.rb, line 8
def initialize(type: 'unknown')
  @elements = []
  @type = type
  super(parent: nil)
end

Public Instance Methods

file_path(target) click to toggle source

@param target [String] name of target @return [String] path to note xml file

# File lib/ooxml_parser/docx_parser/document_structure/page_properties/note.rb, line 51
def file_path(target)
  file = "#{root_object.unpacked_folder}word/#{target}"
  return file if File.exist?(file)

  "#{root_object.unpacked_folder}#{target}" unless File.exist?(file)
end
note_base_xpath() click to toggle source

@return [String] xpath for note in xml object

# File lib/ooxml_parser/docx_parser/document_structure/page_properties/note.rb, line 15
def note_base_xpath
  @note_base_xpath ||= if @type.include?('footer')
                         '//w:ftr'
                       elsif @type.include?('header')
                         '//w:hdr'
                       else
                         raise NameError, "Unknown note type: #{@type}"
                       end
end
parse(params) click to toggle source

Parse note data @param params [Hash] data to parse @return [Note] result of parsing

# File lib/ooxml_parser/docx_parser/document_structure/page_properties/note.rb, line 28
def parse(params)
  @type = params[:type]
  @assigned_to = params[:assigned_to]
  @parent = params[:parent]
  doc = parse_xml(file_path(params[:target]))
  doc.search(note_base_xpath).each do |ftr|
    number = 0
    ftr.xpath('*').each do |sub_element|
      case sub_element.name
      when 'p'
        @elements << params[:default_paragraph].dup.parse(sub_element, number, params[:default_character], parent: self)
        number += 1
      when 'tbl'
        @elements << Table.new(parent: self).parse(sub_element, number)
        number += 1
      end
    end
  end
  self
end