Commit de803e2

mo k <mo@mokhan.ca>
2012-11-04 21:09:16
remove heading method from rover.
1 parent a98cfe9
lib/east.rb
@@ -12,6 +12,9 @@ class East
     location[:x] = location[:x] + 1
     location
   end
+  def represents?(direction)
+    :east == direction
+  end
   def to_s
     'E'
   end
lib/north.rb
@@ -12,6 +12,9 @@ class North
     location[:y] = location[:y].to_i + 1
     location
   end
+  def represents?(direction)
+    :north == direction
+  end
   def to_s
     'N'
   end
lib/rover.rb
@@ -3,18 +3,23 @@ class Rover
     @plateau = plateau
     @location = Location.new(x, y, heading)
   end
-  def heading
-    @location.heading.class.name.downcase.to_sym
-  end
+
   def rotate(degrees)
     @location.rotate(degrees)
   end
+
   def forward
     @plateau.move_forward(@location.heading, @location.location)
   end
+
+  def is_facing(direction)
+    @location.is_facing(direction)
+  end
+
   def location
     @location.location
   end
+
   def to_s
     @location.to_s
   end
@@ -29,6 +34,9 @@ class Location
   def rotate(degrees)
     @heading = @heading.rotate(degrees)
   end
+  def is_facing(direction)
+    @heading.represents? direction
+  end
   def to_s
     "#{@location[:x]} #{@location[:y]} #{@heading}"
   end
lib/south.rb
@@ -12,6 +12,9 @@ class South
     location[:y] = location[:y] - 1
     location
   end
+  def represents?(direction)
+    :south == direction
+  end
   def to_s
     'S'
   end
lib/west.rb
@@ -12,6 +12,9 @@ class West
     location[:x] = location[:x] - 1
     location
   end
+  def represents?(direction)
+    :west == direction
+  end
   def to_s
     'W'
   end
spec/unit/rover_spec.rb
@@ -12,13 +12,13 @@ describe Rover do
     context "when turning right" do
       it "should face east" do
         sut.rotate(90)
-        sut.heading.should == :east
+        sut.is_facing(:east).should be_true
       end
     end
     context "when turning left" do
       it "should face west" do
         sut.rotate(-90)
-        sut.heading.should == :west
+        sut.is_facing(:west).should be_true
       end
     end
   end
@@ -28,13 +28,13 @@ describe Rover do
     context "when turning right" do
       it "should face west" do
         sut.rotate(90)
-        sut.heading.should == :west
+        sut.is_facing(:west).should be_true
       end
     end
     context "when turning left" do
       it "should face east" do
         sut.rotate(-90)
-        sut.heading.should == :east
+        sut.is_facing(:east).should be_true
       end
     end
   end
@@ -45,13 +45,13 @@ describe Rover do
     context "when turning right" do
       it "should face south" do
         sut.rotate(90)
-        sut.heading.should == :south
+        sut.is_facing(:south).should be_true
       end
     end
     context "when turning left" do
       it "should face north" do
         sut.rotate(-90)
-        sut.heading.should == :north
+        sut.is_facing(:north).should be_true
       end
     end
   end
@@ -62,13 +62,13 @@ describe Rover do
     context "when turning right" do
       it "should face north" do
         sut.rotate(90)
-        sut.heading.should == :north
+        sut.is_facing(:north).should be_true
       end
     end
     context "when turning left" do
       it "should face south" do
         sut.rotate(-90)
-        sut.heading.should == :south
+        sut.is_facing(:south).should be_true
       end
     end
   end