Class: Plurimath::Math::Function::UnaryFunction

Inherits:
Core
  • Object
show all
Defined in:
lib/plurimath/math/function/unary_function.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Core

#class_name, #empty_tag, #insert_t_tag, #nary_attr_value, #omml_parameter, #r_element, #tag_name, #validate_function_formula

Constructor Details

#initialize(parameter_one = nil) ⇒ UnaryFunction

Returns a new instance of UnaryFunction.



9
10
11
12
13
# File 'lib/plurimath/math/function/unary_function.rb', line 9

def initialize(parameter_one = nil)
  parameter_one  = parameter_one.to_s if parameter_one.is_a?(Parslet::Slice)
  @parameter_one = parameter_one
  Utility.validate_left_right([parameter_one])
end

Instance Attribute Details

#parameter_oneObject

Returns the value of attribute parameter_one.



7
8
9
# File 'lib/plurimath/math/function/unary_function.rb', line 7

def parameter_one
  @parameter_one
end

Instance Method Details

#==(object) ⇒ Object



15
16
17
18
# File 'lib/plurimath/math/function/unary_function.rb', line 15

def ==(object)
  object.class == self.class &&
    object.parameter_one == parameter_one
end

#to_asciimathObject



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

def to_asciimath
  value = if Utility::UNARY_CLASSES.any?(class_name)
            asciimath_value
          elsif parameter_one
            "(#{asciimath_value})"
          end
  "#{class_name}#{value}"
end

#to_htmlObject



46
47
48
49
50
51
52
53
# File 'lib/plurimath/math/function/unary_function.rb', line 46

def to_html
  first_value = if parameter_one.is_a?(Array)
                  "<i>#{parameter_one.map(&:to_html).join}</i>"
                elsif parameter_one
                  "<i>#{parameter_one.to_html}</i>"
                end
  "<i>#{class_name}</i>#{first_value}"
end

#to_latexObject



41
42
43
44
# File 'lib/plurimath/math/function/unary_function.rb', line 41

def to_latex
  first_value = "{#{latex_value}}" if parameter_one
  "\\#{class_name}#{first_value}"
end

#to_mathml_without_math_tagObject



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

def to_mathml_without_math_tag
  row_tag = Utility.ox_element("mrow")
  tag_name = Utility::UNARY_CLASSES.include?(class_name) ? "mi" : "mo"
  new_arr = [Utility.ox_element(tag_name) << class_name]
  if parameter_one
    new_arr += mathml_value
    Utility.update_nodes(row_tag, new_arr)
  else
    new_arr.first
  end
end

#to_omml_without_math_tagObject



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/plurimath/math/function/unary_function.rb', line 55

def to_omml_without_math_tag
  func   = Utility.ox_element("func", namespace: "m")
  funcpr = Utility.ox_element("funcPr", namespace: "m")
  funcpr << Utility.pr_element("ctrl", true, namespace: "m")
  fname  = Utility.ox_element("fName", namespace: "m")
  mr  = Utility.ox_element("r", namespace: "m")
  rpr = Utility.rpr_element
  mt  = Utility.ox_element("t", namespace: "m") << class_name
  fname << Utility.update_nodes(mr, [rpr, mt])
  me = Utility.ox_element("e", namespace: "m")
  Utility.update_nodes(me, omml_value) if parameter_one
  Utility.update_nodes(
    func,
    [
      funcpr,
      fname,
      me,
    ],
  )
  [func]
end