Class: OoxmlParser::Matrix

Inherits:
OOXMLDocumentObject show all
Defined in:
lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_formula/matrix.rb

Overview

Class for ‘m’ data

Instance Attribute Summary collapse

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) ⇒ Matrix

Returns a new instance of Matrix.



7
8
9
10
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_formula/matrix.rb', line 7

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

Instance Attribute Details

#rowsObject

Returns the value of attribute rows.



5
6
7
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_formula/matrix.rb', line 5

def rows
  @rows
end

Instance Method Details

#parse(node) ⇒ Matrix

Parse Matrix object

Parameters:

  • node (Nokogiri::XML:Element)

    node to parse

Returns:

  • (Matrix)

    result of parsing



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_formula/matrix.rb', line 15

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