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

#intent_namesObject



149
150
151
152
153
154
155
156
157
158
# File 'lib/plurimath/math/function/fenced.rb', line 149

def intent_names
  {
    open_closed_interval: "open-closed-interval",
    closed_open_interval: "closed-open-interval",
    binomial_coefficient: "binomial-coefficient",
    closed_interval: "closed-interval",
    open_interval: "open-interval",
    fenced: ":fenced",
  }
end

#line_breaking(obj) ⇒ Object



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

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)


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

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

#mini_sized_unicode(options:) ⇒ Object



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

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



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

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



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

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



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

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



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

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



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

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
44
# 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),
    options: intent_names,
  )
end

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



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

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



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

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



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

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



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

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