Class: Plurimath::Math::Function::Text

Inherits:
UnaryFunction show all
Defined in:
lib/plurimath/math/function/text.rb

Constant Summary collapse

PARSER_REGEX =
%r{unicode\[:(?<unicode>\w{1,})\]}.freeze

Constants inherited from Core

Core::ALL_PARAMETERS, Core::REPLACABLES

Instance Attribute Summary

Attributes inherited from UnaryFunction

#hide_function_name, #parameter_one

Instance Method Summary collapse

Methods inherited from UnaryFunction

#custom_array_line_breaking, #intent_names, #reprocess_parameter_one, #update, #value_nil?

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, #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_mathml_fields, #variable_value, #variables

Constructor Details

#initialize(parameter_one = "", lang: nil) ⇒ Text

Returns a new instance of Text.



10
11
12
13
# File 'lib/plurimath/math/function/text.rb', line 10

def initialize(parameter_one = "", lang: nil)
  super(parameter_one)
  @lang = lang
end

Instance Method Details

#==(object) ⇒ Object



15
16
17
18
# File 'lib/plurimath/math/function/text.rb', line 15

def ==(object)
  object.class == self.class &&
    object.parameter_one == self.parameter_one
end

#element_order=Object



94
# File 'lib/plurimath/math/function/text.rb', line 94

def element_order=(*); end

#insert_t_tag(display_style, options:) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/plurimath/math/function/text.rb', line 52

def insert_t_tag(display_style, options:)
  r_tag = Utility.ox_element("r", namespace: "m")
  if @lang&.to_s != "omml"
    rpr_tag = Utility.ox_element("rPr", namespace: "m")
    rpr_tag << msty_tag_with_attrs
    r_tag << rpr_tag
  end
  Utility.update_nodes(
    r_tag,
    [omml_nodes(display_style, options: options)],
  )
  [r_tag]
end

#to_asciimathObject



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

def to_asciimath(**)
  "\"#{parse_text('asciimath') || parameter_one}\""
end

#to_asciimath_math_zone(spacing, _, _, options:) ⇒ Object



70
71
72
# File 'lib/plurimath/math/function/text.rb', line 70

def to_asciimath_math_zone(spacing, _, _, options:)
  "#{spacing}#{to_asciimath(options: options)} text\n"
end

#to_htmlObject



36
37
38
# File 'lib/plurimath/math/function/text.rb', line 36

def to_html(**)
  parse_text("html") || parameter_one
end

#to_latexObject



31
32
33
34
# File 'lib/plurimath/math/function/text.rb', line 31

def to_latex(**)
  text_value = parse_text("latex") || parameter_one
  "\\text{#{text_value}}"
end

#to_latex_math_zone(spacing, _, _, options:) ⇒ Object



74
75
76
# File 'lib/plurimath/math/function/text.rb', line 74

def to_latex_math_zone(spacing, _, _, options:)
  "#{spacing}#{to_asciimath(options: options)} text\n"
end

#to_mathml_math_zone(spacing, _, _, options:) ⇒ Object



78
79
80
# File 'lib/plurimath/math/function/text.rb', line 78

def to_mathml_math_zone(spacing, _, _, options:)
  "#{spacing}\"#{dump_mathml(self, options: options)}\" text\n"
end

#to_mathml_without_math_tag(intent) ⇒ Object



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

def to_mathml_without_math_tag(intent, **)
  text = ox_element("mtext")
  return text unless parameter_one

  text << (parse_text("mathml") || parameter_one)
end

#to_omml_math_zone(spacing, _, _, display_style:, options:) ⇒ Object



82
83
84
# File 'lib/plurimath/math/function/text.rb', line 82

def to_omml_math_zone(spacing, _, _, display_style:, options:)
  "#{spacing}\"#{dump_omml(self, display_style, options: options)}\" text\n"
end

#to_omml_without_math_tag(_) ⇒ Object



40
41
42
43
44
# File 'lib/plurimath/math/function/text.rb', line 40

def to_omml_without_math_tag(_, **)
  text = Utility.ox_element("t", namespace: "m")
  text << (parse_text("omml") || parameter_one)
  [text]
end

#to_unicodemathObject



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

def to_unicodemath(**)
  return unless value

  value&.start_with?("\\") ? value : "\"#{(Utility.html_entity_to_unicode(value))}\""
end

#to_unicodemath_math_zone(spacing, _, _, options:) ⇒ Object



86
87
88
# File 'lib/plurimath/math/function/text.rb', line 86

def to_unicodemath_math_zone(spacing, _, _, options:)
  "#{spacing}#{to_unicodemath(options: options)} text\n"
end

#validate_function_formulaObject



66
67
68
# File 'lib/plurimath/math/function/text.rb', line 66

def validate_function_formula
  false
end

#valueObject



90
91
92
# File 'lib/plurimath/math/function/text.rb', line 90

def value
  parameter_one
end

#value=(text) ⇒ Object



96
97
98
99
100
101
102
103
104
105
# File 'lib/plurimath/math/function/text.rb', line 96

def value=(text)
  text = text.join if text.is_a?(Array)
  entities = HTMLEntities.new
  symbols  = Mathml::Constants::UNICODE_SYMBOLS.transform_keys(&:to_s)
  text     = entities.encode(text, :hexadecimal)
  symbols.each do |code, string|
    text = text.gsub(code.downcase, "unicode[:#{string}]")
  end
  self.parameter_one = text
end