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

#ascii_fields_to_print, #class_name, #common_math_zone_conversion, #dump_mathml, #dump_omml, #dump_ox_nodes, #empty_tag, #extract_class_from_text, #extractable?, #filtered_values, #font_style_t_tag, #gsub_spacing, #insert_t_tag, #invert_unicode_symbols, #latex_fields_to_print, #mathml_fields_to_print, #nary_attr_value, #omml_fields_to_print, #omml_nodes, #omml_parameter, #omml_tag_name, #r_element, #tag_name, #validate_function_formula, #validate_mathml_fields

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_asciimath_math_zone(spacing, last = false, _) ⇒ Object



78
79
80
81
82
83
84
85
86
# File 'lib/plurimath/math/function/unary_function.rb', line 78

def to_asciimath_math_zone(spacing, last = false, _)
  new_spacing = gsub_spacing(spacing, last)
  new_arr = [
    "#{spacing}\"#{to_asciimath}\" function apply\n",
    "#{new_spacing}|_ \"#{class_name}\" function name\n",
  ]
  ascii_fields_to_print(parameter_one, { spacing: new_spacing, field_name: "argument", additional_space: "   |_ " , array: new_arr })
  new_arr
end

#to_htmlObject



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

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>#{invert_unicode_symbols}</i>#{first_value}"
end

#to_latexObject



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

def to_latex
  "\\#{class_name}{#{latex_value}}"
end

#to_latex_math_zone(spacing, last = false, _) ⇒ Object



88
89
90
91
92
93
94
95
96
# File 'lib/plurimath/math/function/unary_function.rb', line 88

def to_latex_math_zone(spacing, last = false, _)
  new_spacing = gsub_spacing(spacing, last)
  new_arr = [
    "#{spacing}\"#{to_latex}\" function apply\n",
    "#{new_spacing}|_ \"#{class_name}\" function name\n",
  ]
  latex_fields_to_print(parameter_one, { spacing: new_spacing, field_name: "argument", additional_space: "   |_ " , array: new_arr })
  new_arr
end

#to_mathml_math_zone(spacing, last = false, _) ⇒ Object



98
99
100
101
102
103
104
105
106
# File 'lib/plurimath/math/function/unary_function.rb', line 98

def to_mathml_math_zone(spacing, last = false, _)
  new_spacing = gsub_spacing(spacing, last)
  new_arr = [
    "#{spacing}\"#{dump_mathml(self)}\" function apply\n",
    "#{new_spacing}|_ \"#{class_name}\" function name\n",
  ]
  mathml_fields_to_print(parameter_one, { spacing: new_spacing, field_name: "argument", additional_space: "   |_ ", array: new_arr })
  new_arr
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_math_zone(spacing, last = false, _, display_style:) ⇒ Object



108
109
110
111
112
113
114
115
116
# File 'lib/plurimath/math/function/unary_function.rb', line 108

def to_omml_math_zone(spacing, last = false, _, display_style:)
  new_spacing = gsub_spacing(spacing, last)
  new_arr = [
    "#{spacing}\"#{dump_omml(self, display_style)}\" function apply\n",
    "#{new_spacing}|_ \"#{class_name}\" function name\n",
  ]
  omml_fields_to_print(parameter_one, { spacing: new_spacing, field_name: "argument", additional_space: "   |_ ", array: new_arr, display_style: display_style })
  new_arr
end

#to_omml_without_math_tag(display_style) ⇒ Object



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

def to_omml_without_math_tag(display_style)
  return r_element(class_name, rpr_tag: false) unless parameter_one

  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(display_style)) if parameter_one
  Utility.update_nodes(
    func,
    [
      funcpr,
      fname,
      me,
    ],
  )
  [func]
end