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, 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_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, #nary_intent_name, #omml_fields_to_print, #omml_nodes, #omml_parameter, #omml_tag_name, #ox_element, #prime_unicode?, #r_element, #replacable_values, #result, #separate_table, #set, #tag_name, #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



123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/plurimath/math/function/unary_function.rb', line 123

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



156
157
158
# File 'lib/plurimath/math/function/unary_function.rb', line 156

def intent_names
  { name: ":function" }
end

#reprocess_parameter_one(obj) ⇒ Object



143
144
145
146
147
148
149
150
# File 'lib/plurimath/math/function/unary_function.rb', line 143

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_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



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

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



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

def to_html(options:)
  first_value = if parameter_one.is_a?(Array)
                  "<i>#{parameter_one.map { |val| val.to_html(options: options) }.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



44
45
46
# File 'lib/plurimath/math/function/unary_function.rb', line 44

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

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



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

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



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

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
# File 'lib/plurimath/math/function/unary_function.rb', line 30

def to_mathml_without_math_tag(intent, options:)
  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(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
end

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



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

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



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

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



69
70
71
# File 'lib/plurimath/math/function/unary_function.rb', line 69

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

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



113
114
115
116
117
118
119
120
121
# File 'lib/plurimath/math/function/unary_function.rb', line 113

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



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

def update(value)
  self.parameter_one = value
end

#value_nil?Boolean

Returns:

  • (Boolean)


152
153
154
# File 'lib/plurimath/math/function/unary_function.rb', line 152

def value_nil?
  !parameter_one
end