Class: Plurimath::Math::Function::Fenced

Inherits:
TernaryFunction show all
Defined in:
lib/plurimath/math/function/fenced.rb

Constant Summary

Constants inherited from Core

Core::REPLACABLES

Instance Attribute Summary collapse

Attributes inherited from TernaryFunction

#hide_function_name, #parameter_one, #parameter_three, #parameter_two

Instance Method Summary collapse

Methods inherited from TernaryFunction

#all_values_exist?, #any_value_exist?

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, #linebreak, #mathml_fields_to_print, #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, parameter_two = nil, parameter_three = nil, options = {}) ⇒ Fenced

Returns a new instance of Fenced.



11
12
13
14
15
16
17
18
# File 'lib/plurimath/math/function/fenced.rb', line 11

def initialize(
      parameter_one = nil,
      parameter_two = nil,
      parameter_three = nil,
      options = {})
  super(parameter_one, parameter_two, parameter_three)
  @options = options
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



9
10
11
# File 'lib/plurimath/math/function/fenced.rb', line 9

def options
  @options
end

Instance Method Details

#==(object) ⇒ Object



20
21
22
23
# File 'lib/plurimath/math/function/fenced.rb', line 20

def ==(object)
  super(object) &&
    object.options == options
end

#line_breaking(obj) ⇒ Object



130
131
132
133
134
135
# File 'lib/plurimath/math/function/fenced.rb', line 130

def line_breaking(obj)
  field_values = result(Array(parameter_two))
  return unless field_values.length > 1

  obj.update(value_split(obj, field_values))
end

#mini_sized?Boolean

Returns:

  • (Boolean)


137
138
139
140
141
# File 'lib/plurimath/math/function/fenced.rb', line 137

def mini_sized?
  parameter_one&.mini_sized? ||
    Math::Formula.new(parameter_two)&.mini_sized? ||
    parameter_three&.mini_sized?
end

#mini_sized_unicode(options:) ⇒ Object



143
144
145
146
# File 'lib/plurimath/math/function/fenced.rb', line 143

def mini_sized_unicode(options:)
  fenced_value = parameter_two&.map { |param| param.to_unicodemath(options: options) }&.join
  "#{parameter_one.to_unicodemath(options: options)}#{fenced_value}#{parameter_three.to_unicodemath(options: options)}"
end

#to_asciimath(options:) ⇒ Object



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

def to_asciimath(options:)
  first_value  = parameter_one ? parameter_one.to_asciimath(options: options) : "("
  third_value  = parameter_three ? parameter_three.to_asciimath(options: options) : ")"
  second_value = parameter_two&.map { |param| param.to_asciimath(options: options) }&.join(' ')
  "#{first_value}#{second_value}#{third_value}"
end

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



96
97
98
99
100
101
# File 'lib/plurimath/math/function/fenced.rb', line 96

def to_asciimath_math_zone(spacing, last = false, indent = true, options:)
  filtered_values(parameter_two, lang: :asciimath).map.with_index(1) do |object, index|
    new_last = index == @values.length && last
    object.to_asciimath_math_zone(spacing, new_last, indent, options: options)
  end
end

#to_html(options:) ⇒ Object



45
46
47
48
49
50
# File 'lib/plurimath/math/function/fenced.rb', line 45

def to_html(options:)
  first_value  = "<i>#{symbol_or_paren(parameter_one, lang: :html, options: options)}</i>" if parameter_one
  second_value = parameter_two.map { |param| param.to_html(options: options) }.join if parameter_two
  third_value  = "<i>#{symbol_or_paren(parameter_three, lang: :html, options: options)}</i>" if parameter_three
  "#{first_value}#{second_value}#{third_value}"
end

#to_latex(options:) ⇒ Object



52
53
54
55
56
57
# File 'lib/plurimath/math/function/fenced.rb', line 52

def to_latex(options:)
  fenced_value = parameter_two&.map { |param| param.to_latex(options: options) }&.join(" ")
  first_value  = latex_paren(symbol_or_paren(parameter_one, lang: :latex, options: options))
  second_value = latex_paren(symbol_or_paren(parameter_three, lang: :latex, options: options))
  "#{first_value} #{fenced_value} #{second_value}"
end

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



103
104
105
106
107
108
# File 'lib/plurimath/math/function/fenced.rb', line 103

def to_latex_math_zone(spacing, last = false, indent = true, options:)
  filtered_values(parameter_two, lang: :latex).map.with_index(1) do |object, index|
    new_last = index == @values.length && last
    object.to_latex_math_zone(spacing, new_last, indent, options: options)
  end
end

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



110
111
112
113
114
115
# File 'lib/plurimath/math/function/fenced.rb', line 110

def to_mathml_math_zone(spacing, last = false, indent = true, options:)
  filtered_values(parameter_two, lang: :mathml, options: options).map.with_index(1) do |object, index|
    new_last = index == @values.length && last
    object.to_mathml_math_zone(spacing, new_last, indent, options: options)
  end
end

#to_mathml_without_math_tag(intent, options:) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/plurimath/math/function/fenced.rb', line 32

def to_mathml_without_math_tag(intent, options:)
  first_value = ox_element("mo", attributes: self.options&.dig(:open_paren)) << (mathml_paren(parameter_one, intent, options: options) || "")
  third_value = ox_element("mo", attributes: self.options&.dig(:close_paren)) << (mathml_paren(parameter_three, intent, options: options) || "")
  mrow_value = Array(mathml_value(intent, options: options))&.insert(0, first_value) << third_value
  fenced = Utility.update_nodes(ox_element("mrow"), mrow_value)
  intentify(
    fenced,
    intent,
    func_name: :interval_fence,
    intent_name: intent_value(mrow_value, options: options),
  )
end

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



117
118
119
120
121
# File 'lib/plurimath/math/function/fenced.rb', line 117

def to_omml_math_zone(spacing, last = false, indent = true, display_style:, options:)
  filtered_values(parameter_two, lang: :omml).map do |object|
    object.to_omml_math_zone(spacing, last, !indent, display_style: display_style, options: options)
  end
end

#to_omml_without_math_tag(display_style, options:) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/plurimath/math/function/fenced.rb', line 59

def to_omml_without_math_tag(display_style, options:)
  attrs = { "m:val": (options ? options[:separators] : "") }
  d = Utility.ox_element("d", namespace: "m")
  dpr = Utility.ox_element("dPr", namespace: "m")
  open_paren(dpr, options: options)
  dpr << Utility.ox_element("sepChr", namespace: "m", attributes: attrs)
  close_paren(dpr, options: options)
  Utility.update_nodes(
    d,
    [
      dpr,
      omml_parameter(
        Formula.new(Array(parameter_two)),
        display_style,
        tag_name: "e",
        options: options,
      ),
    ],
  )
  [d]
end

#to_unicodemath(options:) ⇒ Object



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

def to_unicodemath(options:)
  return mini_sized_unicode(options: options) if mini_sized?

  fenced_value = parameter_two&.map do |param|
    next param.choose_frac(options: options) if choose_frac?(param)

    param.to_unicodemath(options: options)
  end&.join(" ")
  return fenced_value if choose_frac?(parameter_two.first)

  fenced_value = "(#{fenced_value})" if vert_paren?

  "#{unicode_open_paren(options: options)}#{fenced_value}#{unicode_close_paren(options: options)}"
end

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



123
124
125
126
127
128
# File 'lib/plurimath/math/function/fenced.rb', line 123

def to_unicodemath_math_zone(spacing, last = false, indent = true, options:)
  filtered_values(parameter_two, lang: :unicodemath).map.with_index(1) do |object, index|
    new_last = index == @values.length && last
    object.to_unicodemath_math_zone(spacing, new_last, indent, options: options)
  end
end