Class: UtcRpnCalc::Calculator

Inherits:
Object
  • Object
show all
Defined in:
lib/utc_rpn_calc/calculator.rb

Constant Summary collapse

FFFF =
"FFFF".hex

Instance Method Summary collapse

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

#calculateObject



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