Sha256: 3def7f3e231be6802a18ec8673a349b3d63162038848fb560ff5de3ccc8b3df8

Contents?: true

Size: 1.04 KB

Versions: 4

Compression:

Stored size: 1.04 KB

Contents

require_relative 'matrix/matrix_row'
module OoxmlParser
  # Class for 'm' data
  class Matrix < OOXMLDocumentObject
    attr_accessor :rows

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

    # Parse Matrix object
    # @param node [Nokogiri::XML:Element] node to parse
    # @return [Matrix] result of parsing
    def parse(node)
      columns_count = 1
      j = 0
      node.xpath('m:mPr').each do |m_pr|
        m_pr.xpath('m:mcs').each do |mcs|
          mcs.xpath('m:mc').each do |mc|
            mc.xpath('m:mcPr').each do |mc_pr|
              mc_pr.xpath('m:count').each do |count|
                columns_count = count.attribute('val').value.to_i
              end
            end
          end
        end
      end

      node.xpath('m:mr').each do |mr|
        i = 0
        @rows << MatrixRow.new(columns_count, parent: self)
        mr.xpath('m:e').each do |e|
          @rows[j].columns[i] = DocxFormula.new(parent: self).parse(e)
          i += 1
        end
        j += 1
      end

      self
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
ooxml_parser-0.4.1 lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_formula/matrix.rb
ooxml_parser-0.4.0 lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_formula/matrix.rb
ooxml_parser-0.3.0 lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_formula/matrix.rb
ooxml_parser-0.2.0 lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_formula/matrix.rb