Sha256: 89554685a81146a624a2bcde8f1e0d39d52b6678c7241a7da92776e974200cb2

Contents?: true

Size: 919 Bytes

Versions: 8

Compression:

Stored size: 919 Bytes

Contents

# frozen_string_literal: true

require_relative 'comments/comment'
module OoxmlParser
  # Class for parsing `comments.xml` file
  class Comments < OOXMLDocumentObject
    # @return [Array<Comment>] list of comments
    attr_reader :comments_array

    def initialize(params = {})
      @comments_array = []
      @parent = params[:parent]
      @file = params.fetch(:file, OOXMLDocumentObject.path_to_folder + 'word/comments.xml')
    end

    # @return [Comment] accessor
    def [](key)
      @comments_array[key]
    end

    # Parse CommentsExtended object
    # @return [Comments] result of parsing
    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
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
ooxml_parser-0.8.1 lib/ooxml_parser/docx_parser/docx_data/document_structure/comments.rb
ooxml_parser-0.8.0 lib/ooxml_parser/docx_parser/docx_data/document_structure/comments.rb
ooxml_parser-0.7.2 lib/ooxml_parser/docx_parser/docx_data/document_structure/comments.rb
ooxml_parser-0.7.1 lib/ooxml_parser/docx_parser/docx_data/document_structure/comments.rb
ooxml_parser-0.7.0 lib/ooxml_parser/docx_parser/docx_data/document_structure/comments.rb
ooxml_parser-0.6.0 lib/ooxml_parser/docx_parser/docx_data/document_structure/comments.rb
ooxml_parser-0.5.1 lib/ooxml_parser/docx_parser/docx_data/document_structure/comments.rb
ooxml_parser-0.5.0 lib/ooxml_parser/docx_parser/docx_data/document_structure/comments.rb