class Rubbot

Public Class Methods

new(grid, options = {}) click to toggle source
# 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

Public Instance Methods

start() click to toggle source
# 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