require "nasa_rovers/rover" module NasaRovers class CLI HELP_FLAGS = %w[-h --help] COL_WIDTH = 23 def initialize(input, pipe=STDOUT, rover_class=Rover) @input = input @pipe = pipe @rover = rover_class end def call @pipe.puts output end private def output return help if help? return unless file? data = File.readlines(@input).map(&:strip) @rover.instruct(data) end private def file? File.file?(File.expand_path(@input)) end private def help? HELP_FLAGS.include?(@input) end private def help [].tap do |h| h << %q{Usage: nasa_rovers ~/nasa_data.txt} h << " %-#{COL_WIDTH}s Print this help" % "-h --help" h << " %-#{COL_WIDTH}s Instruct rovers with NASA data" % "" end end end end