Commit d5c9457

mo k <mo@mokhan.ca>
2012-08-12 22:20:26
change term from turn to rotate.
1 parent 976c985
lib/east.rb
@@ -5,7 +5,7 @@ class East
   def turn_left
     North.new
   end
-  def turn(degrees)
+  def rotate(degrees)
     degrees > 0 ? turn_right : turn_left
   end
   def forward(location)
lib/move_forward.rb
@@ -0,0 +1,11 @@
+class MoveForward
+  def initialize(rover)
+    @rover = rover
+  end
+  def run(instruction)
+    @rover.forward if matches(instruction)
+  end
+  def matches(item)
+    'M' == item
+  end
+end
lib/navigate_rover.rb
@@ -23,47 +23,3 @@ class NavigateRover
     [MoveForward.new(rover), TurnLeft.new(rover), TurnRight.new(rover)]
   end
 end
-
-class MoveForward
-  def initialize(rover)
-    @rover = rover
-  end
-  def run(instruction)
-    @rover.forward if matches(instruction)
-  end
-  def matches(item)
-    'M' == item
-  end
-end
-class TurnLeft
-  def initialize(rover)
-    @rover = rover
-  end
-  def run(instruction)
-    @rover.turn(Left.new) if matches(instruction)
-  end
-  def matches(item)
-    'L' == item
-  end
-end
-class TurnRight
-  def initialize(rover)
-    @rover = rover
-  end
-  def run(instruction)
-    @rover.turn(Right.new) if matches(instruction)
-  end
-  def matches(item)
-    'R' == item
-  end
-end
-class Left
-  def turn_from(heading)
-    heading.turn(-90)
-  end
-end
-class Right
-  def turn_from(heading)
-    heading.turn(90)
-  end
-end
lib/north.rb
@@ -5,7 +5,7 @@ class North
   def turn_left
     West.new
   end
-  def turn(degrees)
+  def rotate(degrees)
     degrees > 0 ? turn_right : turn_left
   end
   def forward(location)
lib/rover.rb
@@ -8,8 +8,8 @@ class Rover
   def heading
     @heading.class.name.downcase.to_sym
   end
-  def turn(direction)
-    @heading = direction.turn_from(@heading)
+  def rotate(degrees)
+    @heading = @heading.rotate(degrees)
   end
   def forward
     @plateau.move_forward(@heading, @location)
lib/south.rb
@@ -5,7 +5,7 @@ class South
   def turn_left
     East.new
   end
-  def turn(degrees)
+  def rotate(degrees)
     degrees > 0 ? turn_right : turn_left
   end
   def forward(location)
lib/turn_left.rb
@@ -0,0 +1,11 @@
+class TurnLeft
+  def initialize(rover)
+    @rover = rover
+  end
+  def run(instruction)
+    @rover.rotate(-90) if matches(instruction)
+  end
+  def matches(item)
+    'L' == item
+  end
+end
lib/turn_right.rb
@@ -0,0 +1,11 @@
+class TurnRight
+  def initialize(rover)
+    @rover = rover
+  end
+  def run(instruction)
+    @rover.rotate(90) if matches(instruction)
+  end
+  def matches(item)
+    'R' == item
+  end
+end
lib/west.rb
@@ -5,7 +5,7 @@ class West
   def turn_left
     South.new
   end
-  def turn(degrees)
+  def rotate(degrees)
     degrees > 0 ? turn_right : turn_left
   end
   def forward(current_location)
spec/unit/rover_spec.rb
@@ -11,13 +11,13 @@ describe Rover do
     let(:sut) { create_sut :north, 0, 0 }
     context "when turning right" do
       it "should face east" do
-        sut.turn(Right.new)
+        sut.rotate(90)
         sut.heading.should == :east
       end
     end
     context "when turning left" do
       it "should face west" do
-        sut.turn(Left.new)
+        sut.rotate(-90)
         sut.heading.should == :west
       end
     end
@@ -27,13 +27,13 @@ describe Rover do
     let(:sut) { create_sut :south, 0, 3 }
     context "when turning right" do
       it "should face west" do
-        sut.turn(Right.new)
+        sut.rotate(90)
         sut.heading.should == :west
       end
     end
     context "when turning left" do
       it "should face east" do
-        sut.turn(Left.new)
+        sut.rotate(-90)
         sut.heading.should == :east
       end
     end
@@ -44,13 +44,13 @@ describe Rover do
 
     context "when turning right" do
       it "should face south" do
-        sut.turn(Right.new)
+        sut.rotate(90)
         sut.heading.should == :south
       end
     end
     context "when turning left" do
       it "should face north" do
-        sut.turn(Left.new)
+        sut.rotate(-90)
         sut.heading.should == :north
       end
     end
@@ -61,13 +61,13 @@ describe Rover do
 
     context "when turning right" do
       it "should face north" do
-        sut.turn(Right.new)
+        sut.rotate(90)
         sut.heading.should == :north
       end
     end
     context "when turning left" do
       it "should face south" do
-        sut.turn(Left.new)
+        sut.rotate(-90)
         sut.heading.should == :south
       end
     end