Class: RubyRobot::Shell

Inherits:
Bombshell::Environment
  • Object
show all
Includes:
Bombshell::Shell
Defined in:
lib/ruby_robot/shell.rb

Constant Summary

Constants included from Bombshell::Shell

Bombshell::Shell::EAST, Bombshell::Shell::NORTH, Bombshell::Shell::REMOVE, Bombshell::Shell::SOUTH, Bombshell::Shell::WEST

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeShell



16
17
18
19
20
21
# File 'lib/ruby_robot/shell.rb', line 16

def initialize
  @logger = Logger.new(STDOUT)
  @logger.formatter = proc { |severity, datetime, progname, msg|
    "#{msg}\n"
  }
end

Instance Attribute Details

#loggerObject (readonly)

Returns the value of attribute logger.



14
15
16
# File 'lib/ruby_robot/shell.rb', line 14

def logger
  @logger
end

Instance Method Details

#LEFTObject



50
51
52
53
# File 'lib/ruby_robot/shell.rb', line 50

def LEFT
  return if @robot.nil?
  @robot.left
end

#MOVEObject



45
46
47
48
# File 'lib/ruby_robot/shell.rb', line 45

def MOVE
  return if @robot.nil?
  @robot.move
end

#PLACE(x, y, direction) ⇒ Object

Place a robot



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# 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) ⇒ Object



60
61
62
63
64
# 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

#RIGHTObject



55
56
57
58
# File 'lib/ruby_robot/shell.rb', line 55

def RIGHT
  return if @robot.nil?
  @robot.right
end