class BabbelExplorer::CLI
CLI
controller
Public Instance Methods
call()
click to toggle source
# File lib/babbel_explorer/cli.rb, line 4 def call puts "\nWelcome to Babbel Explorer!\n".cyan.bold menu end
country_list()
click to toggle source
# File lib/babbel_explorer/cli.rb, line 37 def country_list puts "\nChoose a country by its corresponding number or type 'q' to quit".yellow.bold puts "\nScroll down to view countries\n".yellow puts "\n" BabbelExplorer::Country.all.each_with_index do |country, index| if index == 0 nil else puts "#{index}. #{country.name}".yellow end end puts "\nScroll up to view countries\n".yellow end
exit()
click to toggle source
# File lib/babbel_explorer/cli.rb, line 95 def exit puts "\nThank you for using Babbel Explorer!\n".cyan.bold abort end
explore()
click to toggle source
# File lib/babbel_explorer/cli.rb, line 23 def explore #input = "" #unless input == "q" get_countries country_list get_selection #end explore_more end
explore_more()
click to toggle source
# File lib/babbel_explorer/cli.rb, line 85 def explore_more puts "All done exploring for now? Hit any key to view country list again or type 'exit' to exit.".red input = gets.strip.downcase if input == 'exit' exit else explore end end
get_countries()
click to toggle source
# File lib/babbel_explorer/cli.rb, line 33 def get_countries BabbelExplorer::Scraper.scrape_countries if BabbelExplorer::Country.all.empty? end
get_selection()
click to toggle source
# File lib/babbel_explorer/cli.rb, line 52 def get_selection chosen_country = gets.strip max_countries = BabbelExplorer::Country.all.length - 1 if chosen_country.to_i == 238 puts "\nThere are more than 7,000 languages spoken in the world. Try selecting a specific country:\n".red get_selection elsif chosen_country.to_i > 0 && chosen_country.to_i <= max_countries chosen_country = chosen_country.to_i show_lang_blurb(chosen_country) elsif chosen_country == 'q' explore_more else puts "Invalid command! Please try again.".red.bold get_selection end end
invalid_input()
click to toggle source
# File lib/babbel_explorer/cli.rb, line 70 def invalid_input puts "\nInvalid Command!".red.bold puts "Please try again\n".red menu end
show_lang_blurb(chosen_country)
click to toggle source
# File lib/babbel_explorer/cli.rb, line 76 def show_lang_blurb(chosen_country) countries = BabbelExplorer::Country.all country = countries[chosen_country] puts "\nLanguages spoken in #{country.name}:".magenta.bold puts "#{country.language}".magenta puts "Select another country from the list or type 'q' to quit.".yellow get_selection end