Class: Glimmer::Calculator::Command::Number

Inherits:
Glimmer::Calculator::Command show all
Defined in:
lib/models/glimmer/calculator/command/number.rb

Instance Attribute Summary

Attributes inherited from Glimmer::Calculator::Command

#button, #result

Instance Method Summary collapse

Methods inherited from Glimmer::Calculator::Command

#command_history, command_history, for, #initialize, keyword, keyword_to_command_class_mapping, keywords, #last_command, #last_result, #number1, #number1=, #number2, #number2=, #operation, #operation=

Constructor Details

This class inherits a constructor from Glimmer::Calculator::Command

Instance Method Details

#executeObject



7
8
9
10
11
12
13
14
15
16
# File 'lib/models/glimmer/calculator/command/number.rb', line 7

def execute
  self.result = last_result.nil? || (!last_command.number? && !last_command.point?) ? button : last_result + button
  if operation.nil? || last_command.equals?
    self.number1 = self.result
    self.number2 = nil
    self.operation = nil            
  else
    self.number2 = self.result
  end
end