Class: TripAdvisorBest::CLI
- Inherits:
-
Object
- Object
- TripAdvisorBest::CLI
- Defined in:
- lib/tripadvisor_best/cli.rb
Instance Attribute Summary collapse
-
#sites ⇒ Object
readonly
Returns the value of attribute sites.
Instance Method Summary collapse
- #add_highlight_details(highlight) ⇒ Object
- #call ⇒ Object
- #goodbye ⇒ Object
- #highlight_details(class_name, highlight) ⇒ Object
-
#initialize ⇒ CLI
constructor
A new instance of CLI.
- #list_highlight_details(class_name) ⇒ Object
- #list_hightlights(class_name) ⇒ Object
- #list_options ⇒ Object
- #make_highlights ⇒ Object
- #menu ⇒ Object
- #welcome ⇒ Object
Constructor Details
#initialize ⇒ CLI
Returns a new instance of CLI.
4 5 6 7 8 9 10 11 |
# File 'lib/tripadvisor_best/cli.rb', line 4 def initialize @sites = [ {class_name: TripAdvisorBest::Museum, url: "https://www.tripadvisor.com/TravelersChoice-Museums#1"}, {class_name: TripAdvisorBest::Attraction, url: "https://www.tripadvisor.com/TravelersChoice-Attractions"}, {class_name: TripAdvisorBest::Landmark, url: "https://www.tripadvisor.com/TravelersChoice-Landmarks"} ] make_highlights end |
Instance Attribute Details
#sites ⇒ Object (readonly)
Returns the value of attribute sites.
2 3 4 |
# File 'lib/tripadvisor_best/cli.rb', line 2 def sites @sites end |
Instance Method Details
#add_highlight_details(highlight) ⇒ Object
112 113 114 115 |
# File 'lib/tripadvisor_best/cli.rb', line 112 def add_highlight_details(highlight) attributes = TripAdvisorBest::Scraper.new.scrap_details_page(highlight.url) highlight.add_highlight_attributes(attributes) end |
#call ⇒ Object
22 23 24 25 |
# File 'lib/tripadvisor_best/cli.rb', line 22 def call welcome end |
#goodbye ⇒ Object
117 118 119 |
# File 'lib/tripadvisor_best/cli.rb', line 117 def goodbye puts "Bon voyage!" end |
#highlight_details(class_name, highlight) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/tripadvisor_best/cli.rb', line 99 def highlight_details(class_name, highlight) puts"#{highlight.ranking}. - #{highlight.name} - #{highlight.location}".colorize(:yellow) puts " #{highlight.description}".colorize(:light_blue) puts "----------------------".colorize(:green) puts "Would you like to see another? (y or n)" input = gets.strip.downcase if input == "y" list_highlight_details(class_name) end end |
#list_highlight_details(class_name) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/tripadvisor_best/cli.rb', line 83 def list_highlight_details(class_name) puts "Which would you like to see in greater detail?" input = gets.strip.to_i if input.between?(1, 25) highlight = class_name.find(input - 1) add_highlight_details(highlight) highlight_details(class_name, highlight) else puts "I didn't get that..." list_highlight_details(class_name) end end |
#list_hightlights(class_name) ⇒ Object
77 78 79 80 81 |
# File 'lib/tripadvisor_best/cli.rb', line 77 def list_hightlights(class_name) class_name.all.each do |highlight| puts "#{highlight.ranking}. - #{highlight.name}".colorize(:yellow) end end |
#list_options ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/tripadvisor_best/cli.rb', line 65 def puts "Currently you can see..." puts "" puts <<-DOC 1. Top 25 Museums 2. Top 25 Attractions 3. Top 25 Landmarks DOC puts "" puts "Which would you like to see?" end |
#make_highlights ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/tripadvisor_best/cli.rb', line 13 def make_highlights puts "Planning your next big trip..." self.sites.each do |site| highlights_array = [] highlights_array = TripAdvisorBest::Scraper.new.scrape_listings_page(site[:url]) site[:class_name].create_from_collection(highlights_array) end end |
#menu ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/tripadvisor_best/cli.rb', line 36 def input = nil while input != "exit" input = gets.strip.downcase case input when "1" puts "Here are the top 25 Museums in the world...".colorize(:red) list_hightlights(sites[0][:class_name]) list_highlight_details(sites[0][:class_name]) when "2" puts "Here are the top 25 Attractions in the world...".colorize(:red) list_hightlights(sites[1][:class_name]) list_highlight_details(sites[1][:class_name]) when "3" puts "Here are the top 25 Landmarks in the world...".colorize(:red) list_hightlights(sites[2][:class_name]) list_highlight_details(sites[2][:class_name]) when "list" when "exit" goodbye else puts "I'm not sure what you want. Either type 'list' or 'exit'." puts "" end end end |
#welcome ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/tripadvisor_best/cli.rb', line 27 def welcome puts "" puts "The TripAdvisor Traveler's Choice Awards are out.".colorize(:red) puts "" puts "Are you ready to travel the world?" puts " (Type 'exit' to leave program.)" puts "" end |