Class: Rubbot

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

Instance Method Summary collapse

Constructor Details

#initialize(grid, options = {}) ⇒ Rubbot

Returns a new instance of Rubbot.



11
12
13
14
15
16
# File 'lib/rubbot.rb', line 11

def initialize(grid, options = {})
  # Optionally accept redefined standard I/O
  @stdin  = options.fetch(:stdin)  { STDIN }
  @stdout = options.fetch(:stdout) { STDOUT }
  @robot = Robot.new(grid)
end

Instance Method Details

#startObject



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/rubbot.rb', line 18

def start
  while input = @stdin.gets
    begin
      cmd = Commands::parse(input)
      cmd.execute(@robot, output: @stdout)
    rescue Commands::NoCommandError, RobotInterface::Place::InvalidFormatError => e
      @stdout << "Invalid input: #{e.message}\n"
      @stdout << RobotInterface::Help::print_help
    end
  end
end