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
-
.commands ⇒ Object
Returns the value of attribute commands.
-
.robot ⇒ Object
Returns the value of attribute robot.
Class Method Summary collapse
-
.execute_commands ⇒ Object
Simply executes the commands array.
-
.init(commands_stream, table_size = 5) ⇒ Object
This method is expecting [Array<String>] of commands such as [‘PLACE 0,0,NORTH’, ‘MOVE’, ‘REPORT’].
-
.report(format = 'console') ⇒ Object
This method return the coordinates of Robot on the table and the direction it is facing.
Methods included from CommandParserHelper
Methods included from CommandHelper
#a_valid_place_command?, #command_type, #commands, #directions, #split_place_command
Class Attribute Details
.commands ⇒ Object
Returns the value of attribute commands.
11 12 13 |
# File 'lib/toy_robot_controller.rb', line 11 def commands @commands end |
.robot ⇒ Object
Returns the value of attribute robot.
11 12 13 |
# File 'lib/toy_robot_controller.rb', line 11 def robot @robot end |
Class Method Details
.execute_commands ⇒ Object
Simply executes the commands array.
considerations:
39 40 41 42 43 44 |
# File 'lib/toy_robot_controller.rb', line 39 def execute_commands raise Command::NoValidCommandsFound if @commands.size.zero? raise Command::PlaceCommandNotFound if @commands.select { |c| c.type == 'PLACE' }.size.zero? @commands.each { |command| send_command_to_robot(command) } end |
.init(commands_stream, table_size = 5) ⇒ Object
This method is expecting [Array<String>] of commands such as [‘PLACE 0,0,NORTH’, ‘MOVE’, ‘REPORT’]
17 18 19 20 21 22 23 24 25 |
# File 'lib/toy_robot_controller.rb', line 17 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 end |
.report(format = 'console') ⇒ Object
This method return the coordinates of Robot on the table and the direction it is facing
28 29 30 |
# File 'lib/toy_robot_controller.rb', line 28 def report(format = 'console') @robot.report(format) end |