Class: Inputomatic::ArithmeticInterpreter
- Inherits:
-
Object
- Object
- Inputomatic::ArithmeticInterpreter
- Defined in:
- lib/inputomatic/arithmetic_interpreter.rb
Constant Summary collapse
- CURRENCY_SYMBOLS =
"$£¢€¥₩₪₹₫₴₱₲₳₵₸₺₼₽៛₠₡₢₣₤₥₦₧₨₩₪₫€₭₮₯₰₱₲₳₴₵₶₷₸₹₺₻₼₽₾₿ℳ".chars.freeze
Instance Method Summary collapse
-
#initialize(input, decimal_separator: '.', thousands_separator: ',') ⇒ ArithmeticInterpreter
constructor
A new instance of ArithmeticInterpreter.
- #parse ⇒ Object
Constructor Details
#initialize(input, decimal_separator: '.', thousands_separator: ',') ⇒ ArithmeticInterpreter
Returns a new instance of ArithmeticInterpreter.
5 6 7 8 9 10 11 12 |
# File 'lib/inputomatic/arithmetic_interpreter.rb', line 5 def initialize(input, decimal_separator: '.', thousands_separator: ',') @input = input .gsub(/\s+/, '') .gsub(thousands_separator, '') .gsub(Regexp.union(CURRENCY_SYMBOLS), '') @decimal_separator = decimal_separator @index = 0 end |
Instance Method Details
#parse ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/inputomatic/arithmetic_interpreter.rb', line 14 def parse result = expression if @index < @input.length raise "Unexpected character: #{@input[@index]}" end result end |