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



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

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)


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

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

#mini_sized_unicodeObject



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

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

#to_asciimathObject



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

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

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



91
92
93
94
95
96
# File 'lib/plurimath/math/function/fenced.rb', line 91

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

#to_htmlObject



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

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

#to_latexObject



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

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

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



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

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

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



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

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

#to_mathml_without_math_tagObject



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

def to_mathml_without_math_tag
  first_value = Utility.ox_element("mo", attributes: options&.dig(:open_paren)) << (mathml_paren(parameter_one) || "")
  second_value = parameter_two&.map(&:to_mathml_without_math_tag) || []
  third_value = Utility.ox_element("mo", attributes: options&.dig(:close_paren)) << (mathml_paren(parameter_three) || "")
  Utility.update_nodes(
    Utility.ox_element("mrow"),
    (second_value.insert(0, first_value) << third_value),
  )
end

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



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

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

#to_omml_without_math_tag(display_style) ⇒ Object



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/fenced.rb', line 55

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

#to_unicodemathObject



76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/plurimath/math/function/fenced.rb', line 76

def to_unicodemath
  return mini_sized_unicode if mini_sized?

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

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

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

  "#{unicode_open_paren}#{fenced_value}#{unicode_close_paren}"
end