Class: Plurimath::Math::Function::Text

Inherits:
UnaryFunction show all
Defined in:
lib/plurimath/math/function/text.rb

Instance Attribute Summary

Attributes inherited from UnaryFunction

#parameter_one

Instance Method Summary collapse

Methods inherited from UnaryFunction

#==, #class_name, #initialize, #value_to_asciimath

Constructor Details

This class inherits a constructor from Plurimath::Math::Function::UnaryFunction

Instance Method Details

#parse_text(lang) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/plurimath/math/function/text.rb', line 30

def parse_text(lang)
  regex = %r{\\mbox\{(?<mbox>.{1,})\}|unicode\[:(?<unicode>\w{1,})\]}
  parameter_one.gsub!(regex) do |_text|
    last_match = Regexp.last_match
    if ["mathml", "html"].include?(lang)
      symbol_value(last_match[:unicode]) || last_match[:mbox]
    else
      last_match[:unicode] || last_match[:mbox]
    end
  end
end

#symbol_value(unicode) ⇒ Object



17
18
19
20
# File 'lib/plurimath/math/function/text.rb', line 17

def symbol_value(unicode)
  Mathml::Constants::UNICODE_SYMBOLS.invert[unicode] ||
    Mathml::Constants::SYMBOLS.invert[unicode]
end

#to_asciimathObject



9
10
11
# File 'lib/plurimath/math/function/text.rb', line 9

def to_asciimath
  "\"#{parse_text('asciimath') || parameter_one}\""
end

#to_htmlObject



26
27
28
# File 'lib/plurimath/math/function/text.rb', line 26

def to_html
  parse_text("html") || parameter_one
end

#to_latexObject



22
23
24
# File 'lib/plurimath/math/function/text.rb', line 22

def to_latex
  parse_text("latex") || parameter_one
end

#to_mathml_without_math_tagObject



13
14
15
# File 'lib/plurimath/math/function/text.rb', line 13

def to_mathml_without_math_tag
  "<mtext>#{parse_text('mathml') || parameter_one}</mtext>"
end