class Robotoy::CommandParser
Public Class Methods
new(game: Game.new, commands: ARGF)
click to toggle source
# File lib/robotoy/command_parser.rb, line 3 def initialize(game: Game.new, commands: ARGF) @game = game @commands = commands end
Public Instance Methods
perform()
click to toggle source
# 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 Errors => e puts e.message end end end
Private Instance Methods
set_params(command)
click to toggle source
# File lib/robotoy/command_parser.rb, line 23 def set_params(command) splitted = command.split(/\s+/) @method = splitted[0].strip @args = splitted[1] ? splitted[1].split(',').map(&:strip) : [] end