Class: OoxmlParser::Note
- Inherits:
-
OOXMLDocumentObject
- Object
- OOXMLDocumentObject
- OoxmlParser::Note
- Defined in:
- lib/ooxml_parser/docx_parser/document_structure/page_properties/note.rb
Overview
Class with data of Note
Instance Attribute Summary collapse
-
#assigned_to ⇒ Object
Returns the value of attribute assigned_to.
-
#elements ⇒ Object
Returns the value of attribute elements.
-
#type ⇒ Object
Returns the value of attribute type.
Attributes inherited from OOXMLDocumentObject
Instance Method Summary collapse
-
#file_path(target) ⇒ String
Path to note xml file.
-
#initialize(type: 'unknown') ⇒ Note
constructor
A new instance of Note.
-
#note_base_xpath ⇒ String
Xpath for note in xml object.
-
#parse(params) ⇒ Note
Parse note data.
Methods inherited from OOXMLDocumentObject
#==, #boolean_attribute_value, #parse_xml, #with_data?
Methods included from OoxmlObjectAttributeHelper
#attribute_enabled?, #option_enabled?
Methods included from OoxmlDocumentObjectHelper
Constructor Details
#initialize(type: 'unknown') ⇒ Note
Returns a new instance of Note.
8 9 10 11 12 |
# 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 |
Instance Attribute Details
#assigned_to ⇒ Object
Returns the value of attribute assigned_to.
6 7 8 |
# File 'lib/ooxml_parser/docx_parser/document_structure/page_properties/note.rb', line 6 def assigned_to @assigned_to end |
#elements ⇒ Object
Returns the value of attribute elements.
6 7 8 |
# File 'lib/ooxml_parser/docx_parser/document_structure/page_properties/note.rb', line 6 def elements @elements end |
#type ⇒ Object
Returns the value of attribute type.
6 7 8 |
# File 'lib/ooxml_parser/docx_parser/document_structure/page_properties/note.rb', line 6 def type @type end |
Instance Method Details
#file_path(target) ⇒ String
Returns path to note xml file.
51 52 53 54 55 56 |
# 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 ⇒ String
Returns xpath for note in xml object.
15 16 17 18 19 20 21 22 23 |
# 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) ⇒ Note
Parse note data
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/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 |