Class: Plurimath::Math::Function::Nary

Inherits:
Core
  • Object
show all
Defined in:
lib/plurimath/math/function/nary.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_symbol?, #is_ternary_function?, #is_unary?, #latex_fields_to_print, #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?, #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, parameter_two = nil, parameter_three = nil, parameter_four = nil, options = {}) ⇒ Nary

Returns a new instance of Nary.



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/plurimath/math/function/nary.rb', line 10

def initialize(parameter_one = nil,
               parameter_two = nil,
               parameter_three = nil,
               parameter_four = nil,
               options = {})
  @parameter_one = parameter_one
  @parameter_two = parameter_two
  @parameter_three = parameter_three
  @parameter_four = parameter_four
  @options = options
  Utility.validate_left_right([parameter_one, parameter_two,
                               parameter_three, parameter_four])
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



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

def options
  @options
end

#parameter_fourObject

Returns the value of attribute parameter_four.



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

def parameter_four
  @parameter_four
end

#parameter_oneObject

Returns the value of attribute parameter_one.



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

def parameter_one
  @parameter_one
end

#parameter_threeObject

Returns the value of attribute parameter_three.



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

def parameter_three
  @parameter_three
end

#parameter_twoObject

Returns the value of attribute parameter_two.



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

def parameter_two
  @parameter_two
end

Instance Method Details

#==(object) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/plurimath/math/function/nary.rb', line 24

def ==(object)
  self.class == object.class &&
    object.parameter_one == parameter_one &&
    object.parameter_two == parameter_two &&
    object.parameter_three == parameter_three &&
    object.parameter_four == parameter_four &&
    object.options == options
end

#intent_namesObject



137
138
139
140
141
142
143
144
145
146
147
# File 'lib/plurimath/math/function/nary.rb', line 137

def intent_names
  @@names ||= Symbols::Symbol.descendants.map.with_object({}) do |symbol, hash|
    sym_instance = symbol.new
    next unless sym_instance.is_nary_symbol?

    intent_name = sym_instance.nary_intent_name
    next pp symbol.const_source_location(:INPUT) if intent_name.nil?

    hash[intent_name.gsub(/\s|-/, "_").to_sym] = intent_name
  end
end

#is_nary_function?Boolean

Returns:

  • (Boolean)


149
150
151
# File 'lib/plurimath/math/function/nary.rb', line 149

def is_nary_function?
  true
end

#line_breaking(obj) ⇒ Object



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/plurimath/math/function/nary.rb', line 97

def line_breaking(obj)
  parameter_one&.line_breaking(obj)
  if obj.value_exist?
    obj.update(
      self.class.new(
        Utility.filter_values(obj.value),
        parameter_two,
        parameter_three,
        parameter_four,
        options,
      ),
    )
    self.parameter_two = nil
    self.parameter_three = nil
    self.parameter_four = nil
    return
  end

  parameter_two&.line_breaking(obj)
  if obj.value_exist?
    obj.update(
      self.class.new(
        nil,
        Utility.filter_values(obj.value),
        parameter_three,
        parameter_four,
        options,
      ),
    )
    self.parameter_three = nil
    self.parameter_four = nil
    return
  end

  parameter_four&.line_breaking(obj)
  if obj.value_exist?
    obj.update(Utility.filter_values(obj.value))
  end
end

#to_asciimath(options:) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/plurimath/math/function/nary.rb', line 33

def to_asciimath(options:)
  first_value  = parameter_one&.to_asciimath(options: options) || "int"
  second_value = "_(#{parameter_two.to_asciimath(options: options)})" if parameter_two
  third_value  = "^(#{parameter_three.to_asciimath(options: options)})" if parameter_three
  fourth_value = " #{parameter_four.to_asciimath(options: options)}" if parameter_four
  "#{first_value}#{second_value}#{third_value}#{fourth_value}"
end

#to_latex(options:) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/plurimath/math/function/nary.rb', line 41

def to_latex(options:)
  first_value  = parameter_one&.to_latex(options: options) || "\\int"
  second_value = "_{#{parameter_two.to_latex(options: options)}}" if parameter_two
  third_value  = "^{#{parameter_three.to_latex(options: options)}}" if parameter_three
  fourth_value = " #{parameter_four.to_latex(options: options)}" if parameter_four
  "#{first_value}#{second_value}#{third_value}#{fourth_value}"
end

#to_mathml_without_math_tag(intent, options:) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/plurimath/math/function/nary.rb', line 49

def to_mathml_without_math_tag(intent, options:)
  new_arr = [
    validate_mathml_fields(parameter_one, intent, options: options),
    validate_mathml_fields(parameter_two, intent, options: options),
    validate_mathml_fields(parameter_three, intent, options: options),
  ]
  subsup_tag = Utility.update_nodes(ox_element(tag_name), new_arr)
  masked_tag(subsup_tag) if self.options[:mask]
  return subsup_tag unless parameter_four

  intentify(
    Utility.update_nodes(
      ox_element("mrow"),
      [
        subsup_tag,
        wrap_mrow(
          validate_mathml_fields(parameter_four, intent,
                                 options: options), true
        ),
      ],
    ),
    intent,
    func_name: :naryand,
    intent_name: intent_name,
  )
end

#to_omml_without_math_tag(display_style, options:) ⇒ Object



76
77
78
79
80
81
# File 'lib/plurimath/math/function/nary.rb', line 76

def to_omml_without_math_tag(display_style, options:)
  nary_element = Utility.ox_element("nary", namespace: "m")
  Utility.update_nodes(nary_element,
                       omml_nary_tag(display_style, options: options))
  Array(nary_element)
end

#to_unicodemath(options:) ⇒ Object



83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/plurimath/math/function/nary.rb', line 83

def to_unicodemath(options:)
  first_value = sub_value(options: options) if parameter_two
  second_value = sup_value(options: options) if parameter_three
  if prime_unicode?(parameter_three)
    "#{parameter_one&.to_unicodemath(options: options)}#{second_value}#{first_value}#{naryand_value(
      parameter_four, options: options
    )}"
  else
    "#{parameter_one&.to_unicodemath(options: options)}#{first_value}#{second_value}#{naryand_value(
      parameter_four, options: options
    )}"
  end
end