Class: Plurimath::Unitsml

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

Constant Summary collapse

VALID_UNITSML =

Match ^ followed by content containing letters (indicating variables as exponents, which are invalid) Simplified regex to avoid catastrophic backtracking (ReDoS vulnerability)

/\^\(?-?\d*[a-z]/i

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text) ⇒ Unitsml

Returns a new instance of Unitsml.

Raises:



12
13
14
15
# File 'lib/plurimath/unitsml.rb', line 12

def initialize(text)
  @text = text
  raise Math::ParseError.new(text, :invalid_unitsml) 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

#to_formulaObject



17
18
19
# File 'lib/plurimath/unitsml.rb', line 17

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