Class: NumberMuncher::Parser
- Inherits:
-
Object
- Object
- NumberMuncher::Parser
- Defined in:
- lib/number_muncher/parser.rb
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(value) ⇒ Parser
constructor
A new instance of Parser.
Constructor Details
#initialize(value) ⇒ Parser
Returns a new instance of Parser.
3 4 5 |
# File 'lib/number_muncher/parser.rb', line 3 def initialize(value) @value = value end |
Instance Method Details
#call ⇒ Object
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/number_muncher/parser.rb', line 7 def call return Numeric.new(value) unless value.is_a?(String) return nil if tokens.empty? raise InvalidParseExpression, 'parse requires a single number' unless tokens.size == 1 tokens.first.value rescue ArgumentError, ZeroDivisionError raise InvalidNumber, "#{value} is not valid input to parse." end |