Commit eb04ff7

mo k <mo@mokhan.ca>
2012-11-07 03:26:36
create command to output result.
1 parent aa31398
Changed files (3)
lib/command_processor.rb
@@ -7,7 +7,7 @@ class CommandProcessor
   end
   def run
     while @commands.length > 0 do
-      puts @commands.shift.run
+      @commands.shift.run
     end
   end
 end
lib/console.rb
@@ -11,11 +11,10 @@ class Console
     plateau = ask('enter size of plateau:')
 
     while ((landing = ask('enter landing coordinate (q to quit):')) != 'q') do
-      command = NavigateRover.new(plateau, landing, ask('enter instructions:'))
-      @processor.add(command)
+      @processor.add(create_command_for(plateau, landing))
     end
 
-    @output.puts "#{@processor.run}"
+    @processor.run
   end
 
   private
@@ -25,4 +24,18 @@ class Console
     @output.print '> '
     @input.gets.chomp!
   end
+
+  def create_command_for(plateau, landing)
+    OutputResult.new(NavigateRover.new(plateau, landing, ask('enter instructions:')), @output)
+  end
+end
+
+class OutputResult
+  def initialize(command, output)
+    @command = command
+    @output = output
+  end
+  def run
+    @output.puts "#{@command.run}"
+  end
 end
spec/features/step_definitions/navigation_steps.rb
@@ -5,11 +5,11 @@ Given /^the plateau is (\d+) by (\d+)$/ do |x,y|
   @plateau = "#{x} #{y}"
 end
 
-Given /^the starting position is '(.*)'$/ do |input|
+And /^the starting position is '(.*)'$/ do |input|
   @rover = input
 end
 
-Given /^I move "([^\"]*)"$/ do |instructions|
+And /^I move "([^\"]*)"$/ do |instructions|
   @instructions = instructions
 end