Class: Plurimath::Math::Formula

Inherits:
Object
  • Object
show all
Defined in:
lib/plurimath/math/formula.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value = []) ⇒ Formula

Returns a new instance of Formula.



8
9
10
# File 'lib/plurimath/math/formula.rb', line 8

def initialize(value = [])
  @value = value.is_a?(Array) ? value : [value]
end

Instance Attribute Details

#valueObject

Returns the value of attribute value.



6
7
8
# File 'lib/plurimath/math/formula.rb', line 6

def value
  @value
end

Instance Method Details

#==(object) ⇒ Object



12
13
14
# File 'lib/plurimath/math/formula.rb', line 12

def ==(object)
  object.value == value
end

#mathml_contentObject



34
35
36
# File 'lib/plurimath/math/formula.rb', line 34

def mathml_content
  value.map(&:to_mathml_without_math_tag).join
end

#to_asciimathObject



16
17
18
# File 'lib/plurimath/math/formula.rb', line 16

def to_asciimath
  value.map(&:to_asciimath).join
end

#to_latexObject



38
39
40
# File 'lib/plurimath/math/formula.rb', line 38

def to_latex
  value.map(&:to_latex).join
end

#to_mathmlObject



20
21
22
23
24
25
26
27
28
# File 'lib/plurimath/math/formula.rb', line 20

def to_mathml
  <<~MATHML
    <math xmlns='http://www.w3.org/1998/Math/MathML'>
      <mstyle displaystyle='true'>
        #{mathml_content}
      </mstyle>
    </math>
  MATHML
end

#to_mathml_without_math_tagObject



30
31
32
# File 'lib/plurimath/math/formula.rb', line 30

def to_mathml_without_math_tag
  "<mrow>#{mathml_content}</mrow>"
end