Class: Robot::CommandCentre::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/robot/command_centre.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(command_string) ⇒ Command

Returns a new instance of Command.



26
27
28
29
# File 'lib/robot/command_centre.rb', line 26

def initialize(command_string)
  @command, @args = command_string.split(' ')
  @robot = Robot.instance
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



24
25
26
# File 'lib/robot/command_centre.rb', line 24

def args
  @args
end

#commandObject (readonly)

Returns the value of attribute command.



24
25
26
# File 'lib/robot/command_centre.rb', line 24

def command
  @command
end

#robotObject (readonly)

Returns the value of attribute robot.



24
25
26
# File 'lib/robot/command_centre.rb', line 24

def robot
  @robot
end

Instance Method Details

#executeObject



31
32
33
34
35
# File 'lib/robot/command_centre.rb', line 31

def execute
  return robot.place(args) if place?
  return robot.send(:"#{command.downcase}") if robot.table.placed?
  CommandCentre.instance.say('Does not compute, You must place me first')
end

#place?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/robot/command_centre.rb', line 37

def place?
  command == 'PLACE'
end

#validateObject



41
42
43
# File 'lib/robot/command_centre.rb', line 41

def validate
  COMMANDS.include?(command)
end