Commit 1cbfb78

mo k <mo@mokhan.ca>
2012-11-07 04:19:35
extract run_against method.
1 parent ab0718b
Changed files (1)
lib/navigate_rover.rb
@@ -1,10 +1,3 @@
-require "plateau"
-require "specification"
-require "filtered_command"
-require "move_forward"
-require "turn_left"
-require "turn_right"
-
 class NavigateRover
   def initialize(plateau_size, starting_position, instructions)
     @plateau_size = plateau_size
@@ -13,11 +6,7 @@ class NavigateRover
   end
 
   def run
-    rover = create_plateau(@plateau_size).deploy_rover_to(@heading, @x.to_i, @y.to_i)
-    @instructions.each do |instruction|
-      eval("#{instruction.upcase}Command").new.run(rover)
-    end
-    rover.to_s
+    run_against(create_plateau(@plateau_size).deploy_rover_to(@heading, @x.to_i, @y.to_i))
   end
 
   private
@@ -26,4 +15,11 @@ class NavigateRover
     x,y = plateau_size.split(' ')
     Plateau.new(x,y)
   end
+
+  def run_against(rover)
+    @instructions.each do |instruction|
+      eval("#{instruction.upcase}Command").new.run(rover)
+    end
+    rover.to_s
+  end
 end