Class: OoxmlParser::DocxFormula

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

Overview

Class for formula 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) ⇒ DocxFormula

Returns a new instance of DocxFormula.



25
26
27
28
# File 'lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/docx_formula.rb', line 25

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

Instance Attribute Details

#argument_propertiesArgumentProperties

Returns properties of arguments.

Returns:



23
24
25
# File 'lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/docx_formula.rb', line 23

def argument_properties
  @argument_properties
end

#formula_runObject

Returns the value of attribute formula_run.



21
22
23
# File 'lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/docx_formula.rb', line 21

def formula_run
  @formula_run
end

Instance Method Details

#parse(node) ⇒ DocxFormula

Parse DocxFormula object

Parameters:

  • node (Nokogiri::XML:Element)

    node to parse

Returns:



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/docx_formula.rb', line 33

def parse(node)
  node.xpath('*').each do |node_child|
    case node_child.name
    when 'r'
      @formula_run << MathRun.new(parent: self).parse(node_child)
    when 'box', 'borderBox'
      @formula_run << Box.new(parent: self).parse(node_child)
    when 'func'
      @formula_run << Function.new(parent: self).parse(node_child)
    when 'rad'
      @formula_run << Radical.new(parent: self).parse(node_child)
    when 'e', 'eqArr'
      @formula_run << DocxFormula.new(parent: self).parse(node_child)
    when 'nary'
      @formula_run << Nary.new(parent: self).parse(node_child)
    when 'd'
      @formula_run << Delimiter.new(parent: self).parse(node_child)
    when 'sSubSup', 'sSup', 'sSub'
      @formula_run << Index.new(parent: self).parse(node_child)
    when 'f'
      @formula_run << Fraction.new(parent: self).parse(node_child)
    when 'm'
      @formula_run << Matrix.new(parent: self).parse(node_child)
    when 'bar'
      @formula_run << Bar.new(parent: self).parse(node_child)
    when 'acc'
      @formula_run << Accent.new(parent: self).parse(node_child)
    when 'groupChr'
      @formula_run << GroupChar.new(parent: self).parse(node_child)
    when 'argPr'
      @argument_properties = ArgumentProperties.new(parent: self).parse(node_child)
    when 'sPre'
      @formula_run << PreSubSuperscript.new(parent: self).parse(node_child)
    when 'limUpp', 'limLow'
      @formula_run << Limit.new(parent: self).parse(node_child)
    end
  end
  return nil if @formula_run.empty?

  self
end