Module: ToyRobot::Command::Parser

Defined in:
lib/toy_robot/command/parser.rb,
lib/toy_robot/command/parser/base.rb,
lib/toy_robot/command/parser/left.rb,
lib/toy_robot/command/parser/move.rb,
lib/toy_robot/command/parser/place.rb,
lib/toy_robot/command/parser/right.rb,
lib/toy_robot/command/parser/report.rb

Defined Under Namespace

Classes: Base

Constant Summary collapse

Left =
Base.new(
  msg: :left,
  regex: /\ALEFT\z/
)
Move =
Base.new(
  msg: :move,
  regex: /\AMOVE\z/
)
Place =
Base.new(
  msg: :place,
  regex: /\APLACE \d+,\d+,(NORTH|SOUTH|EAST|WEST)\z/,
  args_extractor: place_args_extractor
)
Right =
Base.new(
  msg: :right,
  regex: /\ARIGHT\z/
)
Report =
Base.new(
  msg: :report,
  regex: /\AREPORT\z/
)

Class Method Summary collapse

Class Method Details

.allObject



18
19
20
# File 'lib/toy_robot/command/parser.rb', line 18

def self.all
  constants(false).reject! { |const| const == :Base }.map { |const| const_get(const) }
end

.parse(string) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/toy_robot/command/parser.rb', line 10

def self.parse(string)
  all.each do |parser|
    command = parser.build_with_match(string)
    return command if command
  end
  nil
end