Commit 45f2f6a
Changed files (6)
lib/filtered_command.rb
@@ -0,0 +1,10 @@
+class FilteredCommand
+ def initialize(command, specification)
+ @command = command
+ @specification = specification
+ end
+ def run(item)
+ @command.run if @specification.matches(item)
+ end
+end
+
lib/move_forward.rb
@@ -6,22 +6,3 @@ class MoveForward
@rover.drive
end
end
-
-class FilteredCommand
- def initialize(command, specification)
- @command = command
- @specification = specification
- end
- def run(item)
- @command.run if @specification.matches(item)
- end
-end
-
-class Specification
- def initialize(criteria)
- @criteria = criteria
- end
- def matches(item)
- @criteria.call(item)
- end
-end
lib/specification.rb
@@ -0,0 +1,8 @@
+class Specification
+ def initialize(criteria)
+ @criteria = criteria
+ end
+ def matches(item)
+ @criteria.call(item)
+ end
+end
lib/turn_left.rb
@@ -2,10 +2,7 @@ class TurnLeft
def initialize(rover)
@rover = rover
end
- def run(instruction)
- @rover.rotate(-90) if matches(instruction)
- end
- def matches(item)
- 'L' == item.upcase
+ def run
+ @rover.rotate(-90)
end
end
lib/turn_right.rb
@@ -2,10 +2,7 @@ class TurnRight
def initialize(rover)
@rover = rover
end
- def run(instruction)
- @rover.rotate(90) if matches(instruction)
- end
- def matches(item)
- 'R' == item.upcase
+ def run
+ @rover.rotate(90)
end
end