Class: Plurimath::Math::Function::UnaryFunction
- Inherits:
-
Core
- Object
- Core
- Plurimath::Math::Function::UnaryFunction
show all
- Defined in:
- lib/plurimath/math/function/unary_function.rb
Direct Known Subclasses
Abs, Arccos, Arcsin, Arctan, Bar, Cancel, Ceil, Cos, Cosh, Cot, Coth, Csc, Csch, Ddot, Deg, Det, Dim, Dot, Exp, Floor, Gcd, Glb, Hat, Hom, Ker, Lcm, Left, Lg, Liminf, Limsup, Linebreak, Ln, Longdiv, Lub, Max, Mbox, Merror, Mglyph, Min, Mpadded, Ms, Msgroup, Msline, None, Norm, Obrace, Phantom, Right, Scarries, Sec, Sech, Sin, Sinh, Sqrt, Substack, Sup, Tan, Tanh, Text, Tilde, Tr, Ubrace, Ul, Vec
Constant Summary
Constants inherited
from Core
Core::ALL_PARAMETERS, Core::REPLACABLES
Instance Attribute Summary collapse
Instance Method Summary
collapse
-
#==(object) ⇒ Object
-
#custom_array_line_breaking(obj) ⇒ Object
-
#initialize(parameter_one = nil) ⇒ UnaryFunction
constructor
A new instance of UnaryFunction.
-
#intent_names ⇒ Object
-
#reprocess_parameter_one(obj) ⇒ Object
-
#to_asciimath(options:) ⇒ Object
-
#to_asciimath_math_zone(spacing, last = false, _, options:) ⇒ Object
-
#to_html(options:) ⇒ Object
-
#to_latex(options:) ⇒ Object
-
#to_latex_math_zone(spacing, last = false, _, options:) ⇒ Object
-
#to_mathml_math_zone(spacing, last = false, _, options:) ⇒ Object
-
#to_mathml_without_math_tag(intent, options:) ⇒ Object
-
#to_omml_math_zone(spacing, last = false, _, display_style:, options:) ⇒ Object
-
#to_omml_without_math_tag(display_style, options: {}) ⇒ Object
-
#to_unicodemath(options:) ⇒ Object
-
#to_unicodemath_math_zone(spacing, last = false, _, options:) ⇒ Object
-
#update(value) ⇒ Object
-
#value_nil? ⇒ Boolean
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_name ⇒ Object
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_one ⇒ Object
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
# File 'lib/plurimath/math/function/unary_function.rb', line 139
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_names ⇒ Object
172
173
174
|
# File 'lib/plurimath/math/function/unary_function.rb', line 172
def intent_names
{ name: ":function" }
end
|
#reprocess_parameter_one(obj) ⇒ Object
159
160
161
162
163
164
165
166
|
# File 'lib/plurimath/math/function/unary_function.rb', line 159
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
89
90
91
92
93
94
95
96
97
|
# File 'lib/plurimath/math/function/unary_function.rb', line 89
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
64
65
66
67
68
69
70
71
|
# File 'lib/plurimath/math/function/unary_function.rb', line 64
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
60
61
62
|
# File 'lib/plurimath/math/function/unary_function.rb', line 60
def to_latex(options:)
"\\#{class_name}{#{latex_value(options: options)}}"
end
|
#to_latex_math_zone(spacing, last = false, _, options:) ⇒ Object
99
100
101
102
103
104
105
106
107
|
# File 'lib/plurimath/math/function/unary_function.rb', line 99
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
109
110
111
112
113
114
115
116
117
|
# File 'lib/plurimath/math/function/unary_function.rb', line 109
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
|
# 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
119
120
121
122
123
124
125
126
127
|
# File 'lib/plurimath/math/function/unary_function.rb', line 119
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
73
74
75
76
77
78
79
80
81
82
83
|
# File 'lib/plurimath/math/function/unary_function.rb', line 73
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
85
86
87
|
# File 'lib/plurimath/math/function/unary_function.rb', line 85
def to_unicodemath(options:)
"#{class_name}#{parameter_one&.to_unicodemath(options: options)}"
end
|
#to_unicodemath_math_zone(spacing, last = false, _, options:) ⇒ Object
129
130
131
132
133
134
135
136
137
|
# File 'lib/plurimath/math/function/unary_function.rb', line 129
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
155
156
157
|
# File 'lib/plurimath/math/function/unary_function.rb', line 155
def update(value)
self.parameter_one = value
end
|
#value_nil? ⇒ Boolean
168
169
170
|
# File 'lib/plurimath/math/function/unary_function.rb', line 168
def value_nil?
!parameter_one
end
|