Commit 6014bc4
Changed files (7)
lib/console.rb
@@ -1,3 +1,4 @@
+require 'heading'
require 'rotation'
Dir[File.dirname(__FILE__) + "/**/*.rb"].each do |file|
require file
lib/east.rb
@@ -1,15 +1,11 @@
class East
include Rotation
+ include Heading
+
def rotate(degrees)
degrees > 0 ? South.new : North.new
end
def forward(location, plateau)
plateau.increment(:x, location)
end
- def represents?(direction)
- :east == direction
- end
- def to_s
- 'E'
- end
end
lib/heading.rb
@@ -0,0 +1,8 @@
+module Heading
+ def represents?(direction)
+ self.class.name.downcase.to_sym == direction
+ end
+ def to_s
+ self.class.name[0]
+ end
+end
lib/north.rb
@@ -1,5 +1,6 @@
class North
include Rotation
+ include Heading
def rotate(degrees)
degrees > 0 ? East.new : West.new
@@ -7,10 +8,4 @@ class North
def forward(location, plateau)
plateau.increment(:y, location)
end
- def represents?(direction)
- :north == direction
- end
- def to_s
- 'N'
- end
end
lib/south.rb
@@ -1,16 +1,11 @@
class South
include Rotation
+ include Heading
def rotate(degrees)
degrees > 0 ? West.new : East.new
end
def forward(location, plateau)
plateau.decrement(:y, location)
end
- def represents?(direction)
- :south == direction
- end
- def to_s
- 'S'
- end
end
lib/west.rb
@@ -1,15 +1,11 @@
class West
include Rotation
+ include Heading
+
def rotate(degrees)
degrees > 0 ? North.new : South.new
end
def forward(location, plateau)
plateau.decrement(:x, location)
end
- def represents?(direction)
- :west == direction
- end
- def to_s
- 'W'
- end
end
spec/spec_helper.rb
@@ -4,6 +4,7 @@ require 'simplecov'
SimpleCov.start
require 'rotation'
+require 'heading'
Dir[File.dirname(__FILE__) + "/../lib/**/*.rb"].each do |file|
require file
end