module CommandParserHelper
CommandParserHelper
is just parsing the command and return a command Struct
Public Instance Methods
parse_command(command)
click to toggle source
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 @param command [String] @return [Struct]
# 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
Private Instance Methods
command_object(type, value, status = '', error = '')
click to toggle source
return command Struct
# File lib/helpers/command_parser_helper.rb, line 38 def command_object(type, value, status = '', error = '') Struct.new(:type, :value, :status, :error).new(type, value, status, error) end
command_value(command)
click to toggle source
returns the value of a comamnd
# File lib/helpers/command_parser_helper.rb, line 31 def command_value(command) return split_place_command(command) if place_command_and_valid?(command) command end
place_command_and_valid?(command)
click to toggle source
check if it is a PLACE command and valid also
# File lib/helpers/command_parser_helper.rb, line 43 def place_command_and_valid?(command) command_type(command) == PLACE && a_valid_place_command?(command) end