Exception: Plurimath::Math::ParseError

Inherits:
StandardError
  • Object
show all
Defined in:
lib/plurimath/errors/parse_error.rb

Instance Method Summary collapse

Constructor Details

#initialize(text, type) ⇒ ParseError

Returns a new instance of ParseError.



6
7
8
9
10
# File 'lib/plurimath/errors/parse_error.rb', line 6

def initialize(text, type)
  @text = text
  @type = type.to_sym
  super(@type == :invalid_unitsml ? unitsml_message : parsing_message)
end

Instance Method Details

#generic_partObject



31
32
33
34
35
36
# File 'lib/plurimath/errors/parse_error.rb', line 31

def generic_part
  <<~MESSAGE.rstrip
    [plurimath] If this is a bug, please report the formula at our issue tracker at:
    [plurimath] https://github.com/plurimath/plurimath/issues
  MESSAGE
end

#parsing_messageObject



12
13
14
15
16
17
18
19
20
21
# File 'lib/plurimath/errors/parse_error.rb', line 12

def parsing_message
  <<~MESSAGE
    [plurimath] Error: Failed to parse the following formula with type `#{@type}`.
    [plurimath] Please first manually validate the formula.
    #{generic_part}
    ---- FORMULA BEGIN ----
    #{@text}
    ---- FORMULA END ----
  MESSAGE
end

#unitsml_messageObject



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

def unitsml_message
  <<~MESSAGE
    [plurimath] Invalid formula `#{@text}`.
    [plurimath] The use of a variable as an exponent is not valid.
    #{generic_part}
  MESSAGE
end