Class: OoxmlParser::Matrix

Inherits:
OOXMLDocumentObject show all
Defined in:
lib/ooxml_parser/docx_parser/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

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

Methods included from OoxmlObjectAttributeHelper

#attribute_enabled?, #option_enabled?

Methods included from OoxmlDocumentObjectHelper

#to_hash

Constructor Details

#initialize(parent: nil) ⇒ Matrix

Returns a new instance of Matrix.



9
10
11
12
# File 'lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/docx_formula/matrix.rb', line 9

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

Instance Attribute Details

#rowsObject

Returns the value of attribute rows.



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

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



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
42
43
44
# File 'lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/docx_formula/matrix.rb', line 17

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|
            count_object = ValuedChild.new(:integer, parent: self).parse(count)
            columns_count = count_object.value
          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