Class: UndercoverTouristCli::CLI
- Inherits:
-
Object
- Object
- UndercoverTouristCli::CLI
- Defined in:
- lib/undercover_tourist_cli.rb
Instance Method Summary collapse
- #attraction_list(city) ⇒ Object
- #call ⇒ Object
- #city_selector ⇒ Object
- #pick_attraction_repeat(city) ⇒ Object
- #results(attraction, city) ⇒ Object
- #select_attraction(city) ⇒ Object
Instance Method Details
#attraction_list(city) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/undercover_tourist_cli.rb', line 31 def attraction_list(city) puts "Gathering information..." if city.attractions.empty? Scraper.scrape_city_attractions(city) puts "-------------------------------" puts "Below is a list of attractions:" puts "-------------------------------" i = 1 city.attractions.each do |attraction| puts "#{i}.".colorize(:red) + " #{attraction}".colorize(:blue) i += 1 end puts "Please select a number from the list above." select_attraction(city) else puts "-------------------------------" puts "Below is a list of attractions:" puts "-------------------------------" i = 1 city.attractions.each do |attraction| puts "#{i}.".colorize(:red) + " #{attraction}".colorize(:blue) i += 1 end puts "Please select a number from the list above." select_attraction(city) end end |
#call ⇒ Object
4 5 6 7 8 9 10 |
# File 'lib/undercover_tourist_cli.rb', line 4 def call puts "---------------------------------" puts "Welcome to the Undercover Tourist" puts "---------------------------------" puts "What city would you like to explore? Type" + " Orlando".colorize(:green) +", " + "Los Angeles".colorize(:yellow)+ ", " + "San Diego".colorize(:blue)+ ", or" + " Exit".colorize(:red) + " to exit." city_selector end |
#city_selector ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/undercover_tourist_cli.rb', line 12 def city_selector input = gets.strip.downcase.split(' ').join('-') if input == "orlando" || input == "los-angeles" || input == "san-diego" city = City.new(input) else puts "Invalid entry. Please try again." city_selector end Scraper.scrape_city_summary(city) puts "Great choice! Here's some more information on " + city.name.colorize(:yellow) + ". " + city.city_summary + " Would you like to learn more about this city's attractions? (Y/N)".colorize(:red) choice = gets.strip.downcase if choice == "Y" || choice == "y" attraction_list(city) else call end end |
#pick_attraction_repeat(city) ⇒ Object
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 105 106 |
# File 'lib/undercover_tourist_cli.rb', line 76 def pick_attraction_repeat(city) choice = gets.strip.downcase case choice when "y" puts "-------------------------------" puts "Below is a list of attractions:" puts "-------------------------------" i = 1 city.attractions.each do |attraction| puts "#{i}.".colorize(:red) + " #{attraction}".colorize(:blue) i += 1 end puts "Please select a number from the list above." select_attraction(city) when "n" puts "Would you like to explore another city (Y/N)?" input = gets.strip.downcase case input when "y" call when "n" exit else puts "Invalid entry. Please type Y for yes or N for no." pick_attraction_repeat(city) end else puts "Invalid entry. Please type Y for yes or N for no." pick_attraction_repeat(city) end end |
#results(attraction, city) ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/undercover_tourist_cli.rb', line 108 def results(attraction, city) puts "---------------------------------------------------".colorize(:red) puts "***#{attraction.name}***" puts "---------------------------------------------------".colorize(:red) puts "" puts "Attraction Description: ".colorize(:red) + attraction.description puts "Attraction Rating: ".colorize(:red) + attraction. puts "Today's Attraction Crowd Size (Scale 1-10): ".colorize(:red) + attraction. puts "Today's Attraction Hours: ".colorize(:red) + attraction.hours puts "Be sure to check out: ".colorize(:red) if attraction.priority_attractions == "N/A" puts "N/A" else attraction.priority_attractions.each do |attraction| puts attraction end end puts "Would you like to check out another attraction? (Y/N)".colorize(:cyan) pick_attraction_repeat(city) exit end |
#select_attraction(city) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/undercover_tourist_cli.rb', line 59 def select_attraction(city) input = gets.strip.to_i if input > Attractions.all.count || input < 0 puts "Invalid entry. Please try again." select_attraction(city) end city.attractions.select.with_index do |val, index| if input == index.to_i + 1 @selected_attraction = val end end puts "Gathering details for #{@selected_attraction}..." Scraper.attraction_details(Attractions.find_by_name(@selected_attraction), city) results(Attractions.find_by_name(@selected_attraction), city) end |