Module: Plurimath::Html::TransformUtility

Defined in:
lib/plurimath/html/transform_utility.rb

Constant Summary collapse

HTML_ENTITY =
/\A&(?:#x[0-9a-f]+|#\d+|[a-z][a-z0-9]+);\z/i

Class Method Summary collapse

Class Method Details

.append_expression(value, expression) ⇒ Object



14
15
16
17
18
# File 'lib/plurimath/html/transform_utility.rb', line 14

def append_expression(value, expression)
  return [value] + expression if expression.is_a?(Array)

  [value, expression]
end

.normalize_sub_sup_value(value) ⇒ Object



47
48
49
50
51
# File 'lib/plurimath/html/transform_utility.rb', line 47

def normalize_sub_sup_value(value)
  return Utility.filter_values(value) if value.is_a?(Array)

  value
end

.normalize_symbol(symbol) ⇒ Object



53
54
55
56
57
58
# File 'lib/plurimath/html/transform_utility.rb', line 53

def normalize_symbol(symbol)
  symbol = symbol.to_s
  return symbol if symbol.match?(HTML_ENTITY)

  Utility.string_to_html_entity(symbol)
end

.sub_sup_value(sub_sup, sub_value: nil, sup_value: nil) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/plurimath/html/transform_utility.rb', line 20

def sub_sup_value(sub_sup, sub_value: nil, sup_value: nil)
  normalized_sub_value = normalize_sub_sup_value(sub_value)
  normalized_sup_value = normalize_sub_sup_value(sup_value)

  if Utility.sub_sup_method?(sub_sup)
    sub_sup.parameter_one = normalized_sub_value if normalized_sub_value
    sub_sup.parameter_two = normalized_sup_value if normalized_sup_value
    sub_sup
  elsif normalized_sub_value && normalized_sup_value
    Math::Function::PowerBase.new(
      sub_sup,
      normalized_sub_value,
      normalized_sup_value,
    )
  elsif normalized_sup_value
    Math::Function::Power.new(
      sub_sup,
      normalized_sup_value,
    )
  else
    Math::Function::Base.new(
      sub_sup,
      normalized_sub_value,
    )
  end
end

.symbol(symbol) ⇒ Object



10
11
12
# File 'lib/plurimath/html/transform_utility.rb', line 10

def symbol(symbol)
  Utility.symbols_class(normalize_symbol(symbol), lang: :html)
end