Class: RoboDog::Robot
- Inherits:
-
Object
- Object
- RoboDog::Robot
- Extended by:
- Forwardable
- Defined in:
- lib/robo_dog/robot.rb
Constant Summary collapse
- DataError =
Class.new(StandardError)
Class Method Summary collapse
Instance Method Summary collapse
- #add_coordinator(coordinator) ⇒ Object
- #execute(mode) ⇒ Object
-
#initialize(args = {}) ⇒ Robot
constructor
A new instance of Robot.
- #left ⇒ Object
- #move ⇒ Object
- #right ⇒ Object
Constructor Details
#initialize(args = {}) ⇒ Robot
Returns a new instance of Robot.
21 22 23 24 25 |
# File 'lib/robo_dog/robot.rb', line 21 def initialize(args = {}) @pose = args[:pose] @commands = args[:commands] || [] @coordinators = args[:coordinators] || [] end |
Class Method Details
Instance Method Details
#add_coordinator(coordinator) ⇒ Object
27 28 29 |
# File 'lib/robo_dog/robot.rb', line 27 def add_coordinator(coordinator) coordinators << coordinator end |
#execute(mode) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/robo_dog/robot.rb', line 31 def execute(mode) case mode when :all commands.map! do |command| self.send(command) nil end commands.compact! when :next command = commands.shift if command self.send(command) true else false end end end |
#left ⇒ Object
61 62 63 64 |
# File 'lib/robo_dog/robot.rb', line 61 def left pose.rotate!(:counter) nil end |
#move ⇒ Object
50 51 52 53 54 |
# File 'lib/robo_dog/robot.rb', line 50 def move adj_pose = pose.adjacent self.pose = adj_pose if coordinators.all? { |c| c.valid_coordinates?(adj_pose.coordinates) } nil end |
#right ⇒ Object
56 57 58 59 |
# File 'lib/robo_dog/robot.rb', line 56 def right pose.rotate!(:clockwise) nil end |