Module: ToyRobotController

Extended by:
CommandParserHelper
Defined in:
lib/toy_robot_controller.rb

Overview

ToyRobotController module which sets up the Robot, Table and execute commands provided

Class Attribute Summary collapse

Class Method Summary collapse

Methods included from CommandParserHelper

parse_command

Methods included from CommandHelper

#a_valid_place_command?, #command_type, #commands, #directions, #split_place_command

Class Attribute Details

.commandsArray<Struct> (readonly)

return Array of commands if present

example: <struct type=“PLACE”, value=[“0”, “0”, “NORTH”], status=“”, error=“”>

Returns:

  • (Array<Struct>)


45
46
47
# File 'lib/toy_robot_controller.rb', line 45

def commands
  @commands
end

.robotToyRobot::Robot (readonly)

return [ToyRobot::Robot] if present

Returns:



39
40
41
# File 'lib/toy_robot_controller.rb', line 39

def robot
  @robot
end

Class Method Details

.init(commands_stream, table_size = 5) ⇒ Object

This method is expecting [Array<String>] of commands such as [‘PLACE 0,0,NORTH’, ‘MOVE’, ‘REPORT’]

Parameters:

  • commands_stream (Array<String>)
  • table_size (Integer) (defaults to: 5)

Raises:



26
27
28
29
30
31
32
33
34
35
# File 'lib/toy_robot_controller.rb', line 26

def init(commands_stream, table_size = 5)
  validate_command_stream(commands_stream)

  @commands_stream = commands_stream
  @table = Surface::Table.new(table_size, table_size)
  @robot = ToyRobot::Robot.new(@table)
  @commands = []
  populate_commands
  execute_commands
end