Class: OoxmlParser::CommentsExtended

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

Overview

Class for parsing ‘commentsExtended.xml` file

Instance Attribute Summary

Attributes inherited from OOXMLDocumentObject

#parent

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

#initialize(parent: nil) ⇒ CommentsExtended

Returns a new instance of CommentsExtended.



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

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

Instance Method Details

#[](key) ⇒ Array, CommentsExtended

Returns accessor.

Returns:



11
12
13
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/comments_extended.rb', line 11

def [](key)
  @comments_extended_array[key]
end

#by_id(id) ⇒ CommentExtended

Returns comment by id.

Parameters:

  • id (Integer)

    id of comment

Returns:



32
33
34
35
36
37
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/comments_extended.rb', line 32

def by_id(id)
  @comments_extended_array.each do |cur_comment|
    return cur_comment if cur_comment.paragraph_id == id
  end
  nil
end

#parseCommentsExtended

Parse CommentsExtended object

Returns:



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/comments_extended.rb', line 17

def parse
  file_to_parse = OOXMLDocumentObject.path_to_folder + 'word/commentsExtended.xml'
  return nil unless File.exist?(file_to_parse)
  doc = Nokogiri::XML(File.open(file_to_parse))
  doc.xpath('w15:commentsEx/*').each do |node_child|
    case node_child.name
    when 'commentEx'
      @comments_extended_array << CommentExtended.new(parent: self).parse(node_child)
    end
  end
  self
end