Commit f10b7a6

mo k <mo@mokhan.ca>
2012-11-07 03:37:29
convert PrintToConsole to Interceptor.
1 parent eb04ff7
Changed files (2)
lib/console.rb
@@ -1,5 +1,6 @@
 require 'navigate_rover'
-require "command_processor"
+require 'command_processor'
+require 'interceptor'
 
 class Console
   def initialize(input, output, processor = CommandProcessor.new)
@@ -26,16 +27,15 @@ class Console
   end
 
   def create_command_for(plateau, landing)
-    OutputResult.new(NavigateRover.new(plateau, landing, ask('enter instructions:')), @output)
+    intercept(NavigateRover.new(plateau, landing, ask('enter instructions:')))
   end
-end
 
-class OutputResult
-  def initialize(command, output)
-    @command = command
-    @output = output
+  def intercept(command)
+    Interceptor.new(command, method(:write_to_console))
   end
-  def run
-    @output.puts "#{@command.run}"
+
+  def write_to_console(command)
+    @output.puts "#{command.run}"
   end
 end
+
lib/interceptor.rb
@@ -0,0 +1,9 @@
+class Interceptor
+  def initialize(command, interceptor)
+    @command = command
+    @interceptor = interceptor
+  end
+  def run
+    @interceptor.call(@command)
+  end
+end