class RubyRobot::Shell

Attributes

logger[R]

Public Class Methods

new() click to toggle source
# File lib/ruby_robot/shell.rb, line 16
def initialize
  @logger = Logger.new(STDOUT)
  @logger.formatter = proc { |severity, datetime, progname, msg|
    "#{msg}\n"
  }
end

Public Instance Methods

LEFT() click to toggle source
# File lib/ruby_robot/shell.rb, line 50
def LEFT
  return if @robot.nil?
  @robot.left
end
MOVE() click to toggle source
# File lib/ruby_robot/shell.rb, line 45
def MOVE
  return if @robot.nil?
  @robot.move
end
PLACE(x, y, direction) click to toggle source

Place a robot

# File lib/ruby_robot/shell.rb, line 26
def PLACE(x, y, direction)
  # Save state in case place is called w/ invalid coords
  orig_robot = @robot
  orig_tabletop = @tabletop
  # TODO: What happens when place is called > 1x per session?
  # Answer under time crunch: just replace the Robot and Tabletop
  @robot = Robot.new(direction)
  @tabletop = NetflixTabletop.new
  begin
    @tabletop.place(@robot, x: x, y: y)
    true
  rescue
    @robot = orig_robot
    @tabletop = orig_tabletop
    @logger.info $!
    false
  end
end
REPORT(to_stderr=true) click to toggle source
# File lib/ruby_robot/shell.rb, line 60
def REPORT(to_stderr=true)
  return nil if @robot.nil?
  @logger.info(@robot.report) if to_stderr
  @robot.report
end
RIGHT() click to toggle source
# File lib/ruby_robot/shell.rb, line 55
def RIGHT
  return if @robot.nil?
  @robot.right
end