module Elevatore::CLI
Public Class Methods
run!()
click to toggle source
# File lib/elevatore/cli.rb, line 5 def self.run! welcome! real_arguments = ARGV-['-v', '-q' , '-h'] if real_arguments.size == 0 @people = "" stdin_welcome get_stdin else real_arguments.each do |argument| parse! argument end end end
Private Class Methods
get_stdin()
click to toggle source
# File lib/elevatore/cli.rb, line 43 def self.get_stdin begin loop do print "> " unless ARGV.include?('-q') person = gets break if person == "exit\n" @people << person end ensure begin Elevatore.calling @people rescue ArgumentError => e puts e.message end end end
instructions()
click to toggle source
# File lib/elevatore/cli.rb, line 80 def self.instructions puts "\n\n`-q` - Output to STDOUT only the travel times." puts "`-v` - Check my version out." puts "`-h` - Take a look at my help menu.\n\n" puts "You have 4 options to make people travel with me.\n\n" puts "*Executing command without arguments:*" puts " - This way you will use STDIN to input people until you type 'exit' or interrupt execution(CTRL-C), so that I can finally take them home.\n\n" puts "*Executing command with arguments:*" puts " - You can pass file paths with one person per line" puts " - You can pass people as a formatted string argument" puts " - You can pass people as a JSON array with people objects inside\n\n" puts "To make it easier for me to understand you please catalog yourselves with the following information:\n\n" puts "attribute_1 - Time in minutes that you plan to begin your travel" puts "attribute_2 - A numeric identification, to make it easier for me to know who you are" puts "attribute_3 - From which floor I should pick you up" puts "attribute_4 - Which floor do you want to go?\n\n\n" puts "When using STDIN or strings in files or arguments, each person should be formatted as follows(without curly brackets):" puts "'{attribute_1}m P{attribute_2} {attribute_3} {attribute_4}'\n\n" puts "When using JSON formatting follow a schema like:" puts "[{enter_at: attribute_1, id: attribute_2, from: attribute_3, to: attribute_4}]\n\n" end
lettering()
click to toggle source
# File lib/elevatore/cli.rb, line 68 def self.lettering puts "This is a scheduling program to organize you humans to travel with me efficiently\n\n" puts "+-+------+ +-+ +-+------+ \\-\\ /-/ /-->\\ ^-----------+ +-------+-+ +------v-¬ +--+------+" puts "|-|------+ | | |-|------+ \\ \\ / / / /-> \\ |----+ +----v +-------|-| + ----¬ | |--|------+" puts "| | | | | | | | | | / / \\ \\ | | | | | | | | / / | | " puts "| +---+ | | | +---+ || || | / \\ | | | | | | | | --- / | +--+ " puts "| +---+ | | | +---+ \\\\ // / /<------\\ \\ | | | | | | | +- < | +--+ " puts "| | | | | | \\\\ // / /<--------\\ \\ | | | | | | | | \\ \\ | | " puts "+--------+ +--------+ +--------+ \\v/ / / \\ \\ | | +-------|-| | | \\ \\ +---------+" puts "+--------+ +--------+ +--------+ --> vv vv vvv +-------+-+ +--+ --> +---------+" end
parse!(argument)
click to toggle source
# File lib/elevatore/cli.rb, line 60 def self.parse! argument if File.file?(argument) Elevatore.calling open(argument).read else Elevatore.calling argument end end
stdin_welcome()
click to toggle source
# File lib/elevatore/cli.rb, line 35 def self.stdin_welcome unless ARGV.include?('-q') puts "Input people that wants to get in through STDOIN" puts "Press ctrl-C when you are finished, or `echo 'exit'` into STDIN." puts "Pay attention to formatting: <Minute>m P<Person ID> <From Floor> <To Floor>" end end
welcome!()
click to toggle source
# File lib/elevatore/cli.rb, line 20 def self.welcome! unless ARGV.include?('-q') puts "\nWelcome to the Elevatore...\n\n" if ARGV.include?('-h') lettering instructions exit elsif ARGV.include?('-v') print "Elevatore v" + Elevatore::VERSION exit end puts "Execute with -h to get help\n\n" end end