Class: UtcRpnCalc::Calculator
- Inherits:
-
Object
- Object
- UtcRpnCalc::Calculator
- Defined in:
- lib/utc_rpn_calc/calculator.rb
Constant Summary collapse
- FFFF =
"FFFF".hex
Instance Method Summary collapse
- #calculate ⇒ Object
-
#initialize(input) ⇒ Calculator
constructor
A new instance of Calculator.
Constructor Details
#initialize(input) ⇒ Calculator
Returns a new instance of Calculator.
10 11 12 13 |
# File 'lib/utc_rpn_calc/calculator.rb', line 10 def initialize(input) @inputs = input.gsub('X', '^').split @stack = [] end |
Instance Method Details
#calculate ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/utc_rpn_calc/calculator.rb', line 15 def calculate @inputs.each do |input| return ERROR unless acceptable_input?(input) process_input(input) end calculated_value.to_formatted_hex end |