Class: Plurimath::Unitsml

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

Constant Summary collapse

VALID_UNITSML =
%r{\^(([^\s][^*\/,"]*?[a-z]+)|(\([^-\d]+\)|[^\(\d-]+))}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text) ⇒ Unitsml

Returns a new instance of Unitsml.

Raises:



10
11
12
13
# File 'lib/plurimath/unitsml.rb', line 10

def initialize(text)
  @text = text
  raise Math::ParseError.new(error_message) if text.match?(VALID_UNITSML)
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



19
20
21
22
23
24
25
26
# File 'lib/plurimath/unitsml.rb', line 19

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



15
16
17
# File 'lib/plurimath/unitsml.rb', line 15

def to_formula
  Math::Function::Unitsml.new(text)
end