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::ALL_PARAMETERS, 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, descendants, #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, inherited, #insert_t_tag, #invert_unicode_symbols, #is_binary_function?, #is_mrow?, #is_mstyle?, #is_nary_function?, #is_nary_symbol?, #is_ternary_function?, #is_unary?, #latex_fields_to_print, #line_breaking, #linebreak?, #mathml_fields_to_print, #mathml_nodes, #mini_sized?, #msty_tag_with_attrs, #nary_attr_value, #nary_intent_name, #omml_fields_to_print, #omml_nodes, #omml_parameter, #omml_tag_name, #ox_element, #paren?, #pretty_print_instance_variables, #prime_unicode?, #r_element, #replacable_values, #result, #separate_table, #set, #symbol?, #tag_name, #to_ms_value, #unicodemath_fields_to_print, #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



157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/plurimath/math/function/unary_function.rb', line 157

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

#intent_namesObject



190
191
192
# File 'lib/plurimath/math/function/unary_function.rb', line 190

def intent_names
  { name: ":function" }
end

#reprocess_parameter_one(obj) ⇒ Object



177
178
179
180
181
182
183
184
# File 'lib/plurimath/math/function/unary_function.rb', line 177

def reprocess_parameter_one(obj)
  new_obj = Formula.new([])
  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_asciimath(options:) ⇒ Object



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

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

#to_asciimath_math_zone(spacing, last = false, _, options:) ⇒ Object



94
95
96
97
98
99
100
101
102
103
104
# File 'lib/plurimath/math/function/unary_function.rb', line 94

def to_asciimath_math_zone(spacing, last = false, _, options:)
  new_spacing = gsub_spacing(spacing, last)
  new_arr = [
    "#{spacing}\"#{to_asciimath(options: options)}\" 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, options: options })
  new_arr
end

#to_html(options:) ⇒ Object



65
66
67
68
69
70
71
72
73
74
# File 'lib/plurimath/math/function/unary_function.rb', line 65

def to_html(options:)
  first_value = if parameter_one.is_a?(Array)
                  "<i>#{parameter_one.map do |val|
                    val.to_html(options: options)
                  end.join}</i>"
                elsif parameter_one
                  "<i>#{parameter_one.to_html(options: options)}</i>"
                end
  "<i>#{invert_unicode_symbols}</i>#{first_value}"
end

#to_latex(options:) ⇒ Object



61
62
63
# File 'lib/plurimath/math/function/unary_function.rb', line 61

def to_latex(options:)
  "\\#{class_name}{#{latex_value(options: options)}}"
end

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



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

def to_latex_math_zone(spacing, last = false, _, options:)
  new_spacing = gsub_spacing(spacing, last)
  new_arr = [
    "#{spacing}\"#{to_latex(options: options)}\" 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, options: options })
  new_arr
end

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



118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/plurimath/math/function/unary_function.rb', line 118

def to_mathml_math_zone(spacing, last = false, _, options:)
  new_spacing = gsub_spacing(spacing, last)
  new_arr = [
    "#{spacing}\"#{dump_mathml(self,
                               options: options)}\" 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, options: options })
  new_arr
end

#to_mathml_without_math_tag(intent, options:) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/plurimath/math/function/unary_function.rb', line 30

def to_mathml_without_math_tag(intent, options:)
  tag_name = if Utility::UNARY_CLASSES.include?(class_name)
               insert_space_tags = true
               "mi"
             else
               "mo"
             end
  new_arr = []
  new_arr << (ox_element(tag_name) << class_name) unless hide_function_name
  unary_element = if parameter_one
                    new_arr += mathml_value(intent, options: options)
                    mrow = ox_element("mrow")
                    Utility.update_nodes(mrow, new_arr)
                    intentify(mrow, intent, func_name: :function,
                                            intent_name: intent_names[:name])
                  else
                    new_arr.first
                  end
  if insert_space_tags && options[:unary_function_spacing]
    Utility.update_nodes(
      ox_element("mrow"),
      [
        ox_element("mo", attributes: { rspace: "thickmathspace" }),
        unary_element,
      ],
    )
  else
    unary_element
  end
end

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



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

def to_omml_math_zone(spacing, last = false, _, display_style:,
options:)
  new_spacing = gsub_spacing(spacing, last)
  new_arr = [
    "#{spacing}\"#{dump_omml(self, display_style,
                             options: options)}\" 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, options: options })
  new_arr
end

#to_omml_without_math_tag(display_style, options: {}) ⇒ Object



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

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

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

#to_unicodemath(options:) ⇒ Object



90
91
92
# File 'lib/plurimath/math/function/unary_function.rb', line 90

def to_unicodemath(options:)
  "#{class_name}#{parameter_one&.to_unicodemath(options: options)}"
end

#to_unicodemath_math_zone(spacing, last = false, _, options:) ⇒ Object



145
146
147
148
149
150
151
152
153
154
155
# File 'lib/plurimath/math/function/unary_function.rb', line 145

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

#update(value) ⇒ Object



173
174
175
# File 'lib/plurimath/math/function/unary_function.rb', line 173

def update(value)
  self.parameter_one = value
end

#value_nil?Boolean

Returns:

  • (Boolean)


186
187
188
# File 'lib/plurimath/math/function/unary_function.rb', line 186

def value_nil?
  !parameter_one
end