Class: TravelLeisure::CLI
- Inherits:
-
Object
- Object
- TravelLeisure::CLI
- Defined in:
- lib/travel_leisure/cli.rb
Overview
code handling CLI display logic and user input
Instance Method Summary collapse
- #alt_menu ⇒ Object
- #good_bye ⇒ Object
- #greeting ⇒ Object
- #list_destinations ⇒ Object
- #menu ⇒ Object
- #menu_helper ⇒ Object
- #print_destination(destination) ⇒ Object
- #select_destination ⇒ Object
- #start ⇒ Object
Instance Method Details
#alt_menu ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/travel_leisure/cli.rb', line 89 def puts "\nWould you like to see another travel guide? Type 'Yes' or 'Y' ".yellow.bold puts "\nWould you like to exit? Type 'E' or 'Exit' ".yellow.bold input = gets.strip.downcase if input == 'yes' || input == 'y' elsif input == 'exit' || input == 'e' good_bye else puts "Sorry, I didn't understand that input.".red.bold end end |
#good_bye ⇒ Object
16 17 18 19 |
# File 'lib/travel_leisure/cli.rb', line 16 def good_bye puts "Thank you for checking out Command Line Travel Guides!".yellow.bold exit! end |
#greeting ⇒ Object
10 11 12 13 14 |
# File 'lib/travel_leisure/cli.rb', line 10 def greeting puts "\nWelcome to Command Line Travel Guides!".blue.bold puts "Would you like to see our list of destinations?".yellow puts "If so, please type 'Yes' or 'Y'!".yellow end |
#list_destinations ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/travel_leisure/cli.rb', line 40 def list_destinations TravelLeisure::Destination.all.each.with_index(1) do |destination, index| puts "#{index}. #{destination.city}, #{destination.country}" end def select_destination puts "\nPlease enter the number of the travel guide you would like to access:".yellow.bold input = gets.strip destination = TravelLeisure::Destination.find(input.to_i) if input == "exit" || input == "e" good_bye elsif input.to_i.between?(1,TravelLeisure::Destination.all.length) print_destination(destination) else puts "Sorry! I didn't understand that input, please try again".red.bold select_destination end end def print_destination(destination) puts "" puts "----------- #{destination.city}, #{destination.country} -----------".blue.bold puts "" puts "Best Time To Visit: #{destination.best_time_to_visit}".green.bold puts "\nTransportation: #{destination.transportation}".green.bold puts "\nWeather: #{destination.weather}".green.bold puts "\nKnow Before Visiting: #{destination.know_before_visiting}".green.bold puts "\nLanguage: #{destination.language}".green.bold puts "\nCurrency: #{destination.currency}".green.bold puts "\nWould you like to read more on #{destination.city}? Please enter 'Y' or 'N'".yellow.bold input = gets.strip.downcase case input when 'y' || 'yes' puts "" puts "More info:".yellow puts "" puts destination.description when 'n' || 'no' when 'exit' good_bye else puts "" puts "Sorry, I didn't understand that input.".red.bold end end def puts "\nWould you like to see another travel guide? Type 'Yes' or 'Y' ".yellow.bold puts "\nWould you like to exit? Type 'E' or 'Exit' ".yellow.bold input = gets.strip.downcase if input == 'yes' || input == 'y' elsif input == 'exit' || input == 'e' good_bye else puts "Sorry, I didn't understand that input.".red.bold end end end |
#menu ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/travel_leisure/cli.rb', line 21 def input = gets.strip.downcase if input == "yes" || input == "y" elsif input == "exit" || input == "e" good_bye else puts "Sorry! I didn't understand that input, please try again".red.bold puts "Would you like to see our list?".yellow puts "If so, please type 'Yes' or 'Y' or exit.".yellow end end |
#menu_helper ⇒ Object
35 36 37 38 |
# File 'lib/travel_leisure/cli.rb', line 35 def list_destinations select_destination end |
#print_destination(destination) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/travel_leisure/cli.rb', line 59 def print_destination(destination) puts "" puts "----------- #{destination.city}, #{destination.country} -----------".blue.bold puts "" puts "Best Time To Visit: #{destination.best_time_to_visit}".green.bold puts "\nTransportation: #{destination.transportation}".green.bold puts "\nWeather: #{destination.weather}".green.bold puts "\nKnow Before Visiting: #{destination.know_before_visiting}".green.bold puts "\nLanguage: #{destination.language}".green.bold puts "\nCurrency: #{destination.currency}".green.bold puts "\nWould you like to read more on #{destination.city}? Please enter 'Y' or 'N'".yellow.bold input = gets.strip.downcase case input when 'y' || 'yes' puts "" puts "More info:".yellow puts "" puts destination.description when 'n' || 'no' when 'exit' good_bye else puts "" puts "Sorry, I didn't understand that input.".red.bold end end |
#select_destination ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/travel_leisure/cli.rb', line 45 def select_destination puts "\nPlease enter the number of the travel guide you would like to access:".yellow.bold input = gets.strip destination = TravelLeisure::Destination.find(input.to_i) if input == "exit" || input == "e" good_bye elsif input.to_i.between?(1,TravelLeisure::Destination.all.length) print_destination(destination) else puts "Sorry! I didn't understand that input, please try again".red.bold select_destination end end |
#start ⇒ Object
4 5 6 7 8 |
# File 'lib/travel_leisure/cli.rb', line 4 def start greeting TravelLeisure::Scraper.new.make_destinations end |