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

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

Constant Summary

Constants inherited from Core

Core::REPLACABLES

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Core

#ascii_fields_to_print, #class_name, #cloned_objects, #common_math_zone_conversion, #dump_mathml, #dump_nodes, #dump_omml, #dump_ox_nodes, #empty_tag, #extract_class_name_from_text, #extractable?, #filtered_values, #font_style_t_tag, #get, #gsub_spacing, #insert_t_tag, #invert_unicode_symbols, #is_binary_function?, #is_nary_function?, #is_nary_symbol?, #is_ternary_function?, #is_unary?, #latex_fields_to_print, #line_breaking, #linebreak, #mathml_fields_to_print, #mini_sized?, #nary_attr_value, #omml_fields_to_print, #omml_nodes, #omml_parameter, #omml_tag_name, #ox_element, #r_element, #replacable_values, #result, #separate_table, #set, #tag_name, #unicodemath_parens, #updated_object_values, #validate_function_formula, #validate_mathml_fields, #variable_value, #variables

Constructor Details

#initialize(parameter_one = nil) ⇒ UnaryFunction

Returns a new instance of UnaryFunction.



9
10
11
12
13
14
# 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
  method(:post_initialize).call if methods.include?(:post_initialize)
  Utility.validate_left_right(variables.map { |var| get(var) })
end

Instance Attribute Details

#hide_function_nameObject

Returns the value of attribute hide_function_name.



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

def hide_function_name
  @hide_function_name
end

#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



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

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

#custom_array_line_breaking(obj) ⇒ Object



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/plurimath/math/function/unary_function.rb', line 111

def custom_array_line_breaking(obj)
  parameter_value = result(parameter_one)
  if parameter_value.size > 1
    breaked_result = parameter_value.first.last.omml_line_break(parameter_value)
    update(Array(breaked_result.shift))
    obj.update(self.class.new(breaked_result.flatten))
    reprocess_parameter_one(obj)
    return
  end

  parameter_one.each.with_index(1) do |object, index|
    object.line_breaking(obj)
    break obj.insert(parameter_one.slice!(index..parameter_one.size)) if obj.value_exist?
  end
end

#reprocess_parameter_one(obj) ⇒ Object



131
132
133
134
135
136
137
138
# File 'lib/plurimath/math/function/unary_function.rb', line 131

def reprocess_parameter_one(obj)
  new_obj = Formula.new([])
  self.line_breaking(new_obj)
  if new_obj.value_exist?
    obj.value.insert(0, Linebreak.new)
    obj.value.insert(0, self.class.new(new_obj.value))
  end
end

#to_asciimathObject



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

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



71
72
73
74
75
76
77
78
79
# File 'lib/plurimath/math/function/unary_function.rb', line 71

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



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

#to_latexObject



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

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

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



81
82
83
84
85
86
87
88
89
# File 'lib/plurimath/math/function/unary_function.rb', line 81

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



91
92
93
94
95
96
97
98
99
# File 'lib/plurimath/math/function/unary_function.rb', line 91

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



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

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

#to_omml_math_zone(spacing, last = false, _, display_style:) ⇒ Object



101
102
103
104
105
106
107
108
109
# File 'lib/plurimath/math/function/unary_function.rb', line 101

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



55
56
57
58
59
60
61
62
63
64
65
# File 'lib/plurimath/math/function/unary_function.rb', line 55

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

  if @hide_function_name
    value = omml_value(display_style)
  else
    func = Utility.ox_element("func", namespace: "m")
    value = Utility.update_nodes(func, function_values(display_style))
  end
  Array(value)
end

#to_unicodemathObject



67
68
69
# File 'lib/plurimath/math/function/unary_function.rb', line 67

def to_unicodemath
  "#{class_name}#{parameter_one&.to_unicodemath}"
end

#update(value) ⇒ Object



127
128
129
# File 'lib/plurimath/math/function/unary_function.rb', line 127

def update(value)
  self.parameter_one = value
end

#value_nil?Boolean

Returns:

  • (Boolean)


140
141
142
# File 'lib/plurimath/math/function/unary_function.rb', line 140

def value_nil?
  !parameter_one
end