Sha256: f020118a69f45497a040ea36aed875a9aac8893c44ed0823674d4df8558b2d6a

Contents?: true

Size: 924 Bytes

Versions: 28

Compression:

Stored size: 924 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 = []
      @file = params.fetch(:file, "#{OOXMLDocumentObject.path_to_folder}word/comments.xml")
      super(parent: params[:parent])
    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

28 entries across 28 versions & 1 rubygems

Version Path
ooxml_parser-0.29.0 lib/ooxml_parser/docx_parser/document_structure/comments.rb
ooxml_parser-0.28.0 lib/ooxml_parser/docx_parser/document_structure/comments.rb
ooxml_parser-0.27.0 lib/ooxml_parser/docx_parser/document_structure/comments.rb
ooxml_parser-0.26.0 lib/ooxml_parser/docx_parser/document_structure/comments.rb
ooxml_parser-0.25.0 lib/ooxml_parser/docx_parser/document_structure/comments.rb
ooxml_parser-0.24.0 lib/ooxml_parser/docx_parser/document_structure/comments.rb
ooxml_parser-0.23.0 lib/ooxml_parser/docx_parser/docx_data/document_structure/comments.rb
ooxml_parser-0.22.0 lib/ooxml_parser/docx_parser/docx_data/document_structure/comments.rb
ooxml_parser-0.21.0 lib/ooxml_parser/docx_parser/docx_data/document_structure/comments.rb
ooxml_parser-0.20.0 lib/ooxml_parser/docx_parser/docx_data/document_structure/comments.rb
ooxml_parser-0.19.0 lib/ooxml_parser/docx_parser/docx_data/document_structure/comments.rb
ooxml_parser-0.18.1 lib/ooxml_parser/docx_parser/docx_data/document_structure/comments.rb
ooxml_parser-0.18.0 lib/ooxml_parser/docx_parser/docx_data/document_structure/comments.rb
ooxml_parser-0.17.0 lib/ooxml_parser/docx_parser/docx_data/document_structure/comments.rb
ooxml_parser-0.16.0 lib/ooxml_parser/docx_parser/docx_data/document_structure/comments.rb
ooxml_parser-0.15.0 lib/ooxml_parser/docx_parser/docx_data/document_structure/comments.rb
ooxml_parser-0.14.2 lib/ooxml_parser/docx_parser/docx_data/document_structure/comments.rb
ooxml_parser-0.14.1-mingw32 lib/ooxml_parser/docx_parser/docx_data/document_structure/comments.rb
ooxml_parser-0.14.1 lib/ooxml_parser/docx_parser/docx_data/document_structure/comments.rb
ooxml_parser-0.14.0 lib/ooxml_parser/docx_parser/docx_data/document_structure/comments.rb