Class: Plurimath::Unitsml
- Inherits:
-
Object
- Object
- Plurimath::Unitsml
- Defined in:
- lib/plurimath/unitsml.rb
Instance Attribute Summary collapse
-
#text ⇒ Object
Returns the value of attribute text.
Instance Method Summary collapse
- #error_message ⇒ Object
-
#initialize(text) ⇒ Unitsml
constructor
A new instance of Unitsml.
- #to_formula ⇒ Object
Constructor Details
#initialize(text) ⇒ Unitsml
Returns a new instance of Unitsml.
8 9 10 11 |
# File 'lib/plurimath/unitsml.rb', line 8 def initialize(text) @text = text raise Math::ParseError.new() if text.match?(/\^(([^\s][^*\/,"]*?[a-z]+)|(\([^-\d]+\)|[^\(\d-]+))/) end |
Instance Attribute Details
#text ⇒ Object
Returns the value of attribute text.
6 7 8 |
# File 'lib/plurimath/unitsml.rb', line 6 def text @text end |
Instance Method Details
#error_message ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/plurimath/unitsml.rb', line 22 def <<~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_formula ⇒ Object
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 |