Module: CommandParserHelper

Includes:
CommandHelper
Included in:
ToyRobotController
Defined in:
lib/helpers/command_parser_helper.rb

Overview

CommandParserHelper is just parsing the command and return a command Struct

Instance Method Summary collapse

Methods included from CommandHelper

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

Instance Method Details

#parse_command(command) ⇒ Struct

it the provided command is valid, it will return a Struct with with type, value, status, error attributes

type represents the type of command such as PLACE, MOVE, REPORT, LEFT, RIGHT

value represents the value it holds such value will be X,Y,F for PLACE command

status and error attributes are set to empty in the start

Parameters:

  • command (String)

Returns:

  • (Struct)


20
21
22
23
24
25
26
# File 'lib/helpers/command_parser_helper.rb', line 20

def parse_command(command)
  type_of_command = command_type(command)
  return if type_of_command.nil?
  return if type_of_command == PLACE && a_valid_place_command?(command) == false

  command_object(type_of_command, command_value(command))
end