Module: CommandHelper

Included in:
CommandParserHelper
Defined in:
lib/helpers/command_helper.rb

Overview

CommandHelper contains all the helper methods to valid integrity and type of a command

Instance Method Summary collapse

Instance Method Details

#a_valid_place_command?(command) ⇒ Boolean

it will validate the provided command against the PLACE_COMMAND_PATTERN set in the application_contants

Returns:



9
10
11
12
13
# File 'lib/helpers/command_helper.rb', line 9

def a_valid_place_command?(command)
  return false if command.match(PLACE_COMMAND_PATTERN).nil?

  true
end

#command_type(command) ⇒ String

it will return type of command such as PLACE, MOVE, LEFT, RIGHT, REPORT

Returns:



22
23
24
25
26
# File 'lib/helpers/command_helper.rb', line 22

def command_type(command)
  return if command.nil?
  return PLACE if command.include? PLACE
  return command if COMMANDS.include? command
end

#commandsArray

return all valid commands array [MOVE LEFT RIGHT REPORT PLACE]

Returns:



36
37
38
# File 'lib/helpers/command_helper.rb', line 36

def commands
  COMMANDS
end

#directionsArray

return all directions array [NORTH EAST SOUTH WEST]

Returns:



30
31
32
# File 'lib/helpers/command_helper.rb', line 30

def directions
  DIRECTIONS
end

#split_place_command(place_command) ⇒ Object



15
16
17
18
# File 'lib/helpers/command_helper.rb', line 15

def split_place_command(place_command)
  result = place_command.match(PLACE_COMMAND_PATTERN)
  result&.captures
end