Class: Plurimath::Unitsml

Inherits:
Object
  • Object
show all
Defined in:
lib/plurimath/unitsml.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text) ⇒ Unitsml

Returns a new instance of Unitsml.

Raises:



8
9
10
11
# File 'lib/plurimath/unitsml.rb', line 8

def initialize(text)
  @text = text
  raise Math::ParseError.new(error_message) if text.match?(/\^(([^\s][^*\/,"]*?[a-z]+)|(\([^-\d]+\)|[^\(\d-]+))/)
end

Instance Attribute Details

#textObject

Returns the value of attribute text.



6
7
8
# File 'lib/plurimath/unitsml.rb', line 6

def text
  @text
end

Instance Method Details

#error_messageObject



22
23
24
25
26
27
28
29
# File 'lib/plurimath/unitsml.rb', line 22

def error_message
  <<~MESSAGE
   [plurimath] Invalid formula `#{@text}`.
   [plurimath] The use of a variable as an exponent is not valid.
   [plurimath] If this is a bug, please report the formula at our issue tracker at:
   [plurimath] https://github.com/plurimath/plurimath/issues
  MESSAGE
end

#to_formulaObject



13
14
15
16
17
18
19
20
# File 'lib/plurimath/unitsml.rb', line 13

def to_formula
  unitsml = ::Unitsml.parse(text)
  formula = unitsml.to_plurimath
  formula.unitsml = true
  formula.input_string = text
  formula.unitsml_xml = unitsml.to_xml
  formula
end