Class: BabbelExplorer::CLI
- Inherits:
-
Object
- Object
- BabbelExplorer::CLI
- Defined in:
- lib/babbel_explorer/cli.rb
Overview
CLI controller
Instance Method Summary collapse
- #call ⇒ Object
- #country_list ⇒ Object
- #exit ⇒ Object
- #explore ⇒ Object
- #explore_more ⇒ Object
- #get_countries ⇒ Object
- #get_selection ⇒ Object
- #invalid_input ⇒ Object
- #menu ⇒ Object
- #show_lang_blurb(chosen_country) ⇒ Object
Instance Method Details
#call ⇒ Object
4 5 6 7 |
# File 'lib/babbel_explorer/cli.rb', line 4 def call puts "\nWelcome to Babbel Explorer!\n".cyan.bold end |
#country_list ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# 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 ⇒ Object
95 96 97 98 |
# File 'lib/babbel_explorer/cli.rb', line 95 def exit puts "\nThank you for using Babbel Explorer!\n".cyan.bold abort end |
#explore ⇒ Object
23 24 25 26 27 28 29 30 31 |
# 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 ⇒ Object
85 86 87 88 89 90 91 92 93 |
# 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 ⇒ Object
33 34 35 |
# File 'lib/babbel_explorer/cli.rb', line 33 def get_countries BabbelExplorer::Scraper.scrape_countries if BabbelExplorer::Country.all.empty? end |
#get_selection ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# 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 ⇒ Object
70 71 72 73 74 |
# File 'lib/babbel_explorer/cli.rb', line 70 def invalid_input puts "\nInvalid Command!".red.bold puts "Please try again\n".red end |
#menu ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/babbel_explorer/cli.rb', line 9 def puts "\nTo view country list, type 'explore'\n".green puts "Type 'exit' to exit.".green input = gets.strip case input.downcase when "explore" explore when "exit" exit else invalid_input end end |
#show_lang_blurb(chosen_country) ⇒ Object
76 77 78 79 80 81 82 83 |
# 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 |