Class: BalboaParkItineraryIdeas::CLI
- Inherits:
-
Object
- Object
- BalboaParkItineraryIdeas::CLI
- Defined in:
- lib/balboa_park_itinerary_ideas/cli.rb
Overview
The CLI Controller - responsible for business logic/user interactions
Instance Method Summary collapse
- #call ⇒ Object
-
#goodbye ⇒ Object
displays exit message to the user.
-
#list_itineraries ⇒ Object
lists the itineraries for the user to choose from.
-
#menu ⇒ Object
displays the user’s choices, gets the user’s input, and either displays details of an itinerary, the list of itineraries, or exits.
-
#print_details(itinerary) ⇒ Object
displays the itinerary’s details: title, summary, and each attraction’s name, description, and URL (if has one).
- #start ⇒ Object
-
#welcome_message ⇒ Object
displays scraped welome header and message.
Instance Method Details
#call ⇒ Object
4 5 6 7 8 9 10 11 12 |
# File 'lib/balboa_park_itinerary_ideas/cli.rb', line 4 def call @s = BalboaParkItineraryIdeas::Scraper.new @s.scrape_itineraries @welcome_header = @s.scrape_welcome_header @welcome_message = @s. @header = @s.scrape_header start end |
#goodbye ⇒ Object
displays exit message to the user
87 88 89 |
# File 'lib/balboa_park_itinerary_ideas/cli.rb', line 87 def goodbye puts "\nGoodbye! Comeback soon!\n".green.bold end |
#list_itineraries ⇒ Object
lists the itineraries for the user to choose from
31 32 33 34 35 36 37 |
# File 'lib/balboa_park_itinerary_ideas/cli.rb', line 31 def list_itineraries puts "\n#{@header}".blue.bold BalboaParkItineraryIdeas::Itinerary.all.each.with_index(1) do |itinerary, i| puts "#{i}.".red.bold + " #{itinerary.title}".bold end end |
#menu ⇒ Object
displays the user’s choices, gets the user’s input, and either displays details of an itinerary, the list of itineraries, or exits
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 |
# File 'lib/balboa_park_itinerary_ideas/cli.rb', line 40 def input = nil while input != "exit" puts @border puts "What would you like to do? Your choices are:".green.bold puts "Type the itinerary number " + "('1', '2', '3'....'9')".red.bold + " to see the details" puts "Type " + "list".red.bold + " to see the list again" puts "Type " + "exit".red.bold puts @border input = gets.strip.downcase if input.to_i.between?(1,9) itinerary = BalboaParkItineraryIdeas::Itinerary.find(input.to_i) # Prevent scraping for the selected itinerary's details if the details were already scraped @s.scrape_itinerary_page(itinerary) unless !itinerary.summary.nil? print_details(itinerary) elsif input == "list" list_itineraries elsif input == "exit" goodbye else puts "Didn't understand, please try again." end end end |
#print_details(itinerary) ⇒ Object
displays the itinerary’s details: title, summary, and each attraction’s name, description, and URL (if has one)
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/balboa_park_itinerary_ideas/cli.rb', line 69 def print_details(itinerary) puts "\n#{itinerary.title}".blue.bold puts Strings.wrap(itinerary.summary, 86).yellow itinerary.attractions.each do |attraction| puts "\n#{attraction[:name]}".bold.red puts Strings.wrap(attraction[:description], 75) unless attraction[:attraction_url].nil? puts "Click for more info: ".green.bold + "#{attraction[:attraction_url]}".green.underline end end puts "\nClick below for more information about the ".red + "#{itinerary.title} Itinerary:".red.bold puts "#{itinerary.url}\n".green.underline end |
#start ⇒ Object
14 15 16 17 18 |
# File 'lib/balboa_park_itinerary_ideas/cli.rb', line 14 def start list_itineraries end |
#welcome_message ⇒ Object
displays scraped welome header and message
21 22 23 24 25 26 27 28 |
# File 'lib/balboa_park_itinerary_ideas/cli.rb', line 21 def @border = "------------------------------------------------------------------------------" puts @border puts "#{@welcome_header}".blue.bold puts Strings.wrap(@welcome_message, 80) puts @border end |