Class: OoxmlParser::Comments

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

Overview

Class for parsing ‘comments.xml` file

Instance Attribute Summary collapse

Attributes inherited from OOXMLDocumentObject

#parent

Instance Method Summary collapse

Methods inherited from OOXMLDocumentObject

#==, #boolean_attribute_value, #parse_xml, #with_data?

Methods included from OoxmlObjectAttributeHelper

#attribute_enabled?, #option_enabled?

Methods included from OoxmlDocumentObjectHelper

#to_hash

Constructor Details

#initialize(params = {}) ⇒ Comments

Returns a new instance of Comments.



10
11
12
13
14
# File 'lib/ooxml_parser/docx_parser/document_structure/comments.rb', line 10

def initialize(params = {})
  @comments_array = []
  super(parent: params[:parent])
  @file = params.fetch(:file, "#{root_object.unpacked_folder}word/comments.xml")
end

Instance Attribute Details

#comments_arrayArray<Comment> (readonly)

Returns list of comments.

Returns:

  • (Array<Comment>)

    list of comments



8
9
10
# File 'lib/ooxml_parser/docx_parser/document_structure/comments.rb', line 8

def comments_array
  @comments_array
end

Instance Method Details

#[](key) ⇒ Comment

Returns accessor.

Returns:



17
18
19
# File 'lib/ooxml_parser/docx_parser/document_structure/comments.rb', line 17

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

#parseComments

Parse CommentsExtended object

Returns:



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/ooxml_parser/docx_parser/document_structure/comments.rb', line 23

def parse
  return nil unless File.file?(@file)

  doc = parse_xml(@file)
  doc.xpath('w:comments/*').each do |node_child|
    case node_child.name
    when 'comment'
      @comments_array << Comment.new(parent: self).parse(node_child)
    end
  end
  self
end