Class: Robotoy::CommandParser

Inherits:
Object
  • Object
show all
Defined in:
lib/robotoy/command_parser.rb

Instance Method Summary collapse

Constructor Details

#initialize(game: Game.new, commands: ARGF) ⇒ CommandParser

Returns a new instance of CommandParser.



3
4
5
6
# File 'lib/robotoy/command_parser.rb', line 3

def initialize(game: Game.new, commands: ARGF)
  @game = game
  @commands = commands
end

Instance Method Details

#performObject



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/robotoy/command_parser.rb', line 8

def perform
  @commands.each_line do |command|
    begin
      next if command.strip.empty?
      puts command
      set_params(command)
      @game.perform(@method, @args)
    rescue
      puts "Something went wrong"
    end
  end
end