Sha256: f115f6f1fd2dd8e3e819aba05b816bfbd48d1de0746d00a2fb30f9281e42a28a
Contents?: true
Size: 862 Bytes
Versions: 1
Compression:
Stored size: 862 Bytes
Contents
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" % "<path-to-file>" end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
nasa_rovers-1.0.1 | lib/nasa_rovers/cli.rb |