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

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#class_nameObject



72
73
74
# File 'lib/plurimath/math/function/unary_function.rb', line 72

def class_name
  self.class.name.split("::").last.downcase
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



42
43
44
45
46
47
48
49
# File 'lib/plurimath/math/function/unary_function.rb', line 42

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



37
38
39
40
# File 'lib/plurimath/math/function/unary_function.rb', line 37

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
# 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]
  new_arr += mathml_value if parameter_one
  Utility.update_nodes(row_tag, new_arr)
end

#to_omml_without_math_tagObject



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/plurimath/math/function/unary_function.rb', line 51

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,
    ],
  )
end