class DallasMarsRover::MarsRover
The main Mars Rover
class
Attributes
commander[R]
file[R]
rover[R]
zone[R]
Public Instance Methods
start()
click to toggle source
@return [String] the resulting rover location
# File lib/mars_rover/mars_rover.rb, line 5 def start # Validate we have only files in the argument list abort('ABORTED! Supply a command file') unless valid_arguments? # Exit if we cant create the main processor abort('ABORTED! Invalid commands in file') unless create_commander # Create mars zone create_zone # Create mars rover create_rover # Everything ready, Lets drive! start_driving # Display end location display_location end
Private Instance Methods
create_commander()
click to toggle source
@return [@commander] main app processor object
# File lib/mars_rover/mars_rover.rb, line 25 def create_commander @commander ||= Commander.new @file end
create_rover()
click to toggle source
@return [@rover] the mars rover vehicle object
# File lib/mars_rover/mars_rover.rb, line 35 def create_rover @rover ||= Rover.new @commander, @zone end
create_zone()
click to toggle source
@return [@zone] the survey zone object
# File lib/mars_rover/mars_rover.rb, line 30 def create_zone @zone ||= Zone.new @commander end
display_location()
click to toggle source
@return [String] shows the end result co-ordinates
# File lib/mars_rover/mars_rover.rb, line 45 def display_location puts "#{rover.pos_x} #{rover.pos_y} #{rover.direction}" end
start_driving()
click to toggle source
@return [Boolean] drive status operation
# File lib/mars_rover/mars_rover.rb, line 40 def start_driving rover.drive end
valid_arguments?()
click to toggle source
@return [Boolean] if arguments are valid
# File lib/mars_rover/mars_rover.rb, line 50 def valid_arguments? # Loop through the list, removing anything that is not a valid file ARGV.each do |filename| ARGV.delete(filename) unless File.file?(filename) end # After processing, anything left? and only one input file return false unless ARGV.length == 1 @file = File.open ARGV.join end