Class: Destination
- Inherits:
-
Object
- Object
- Destination
- Defined in:
- lib/top_25_travel_destinations/destination.rb
Instance Attribute Summary collapse
-
#city ⇒ Object
Returns the value of attribute city.
-
#city_description ⇒ Object
Returns the value of attribute city_description.
-
#country ⇒ Object
Returns the value of attribute country.
-
#list_destinations ⇒ Object
Returns the value of attribute list_destinations.
-
#rank ⇒ Object
Returns the value of attribute rank.
Class Method Summary collapse
- .destination_information(input) ⇒ Object
- .find_destination_by_name(name) ⇒ Object
- .get_destinations ⇒ Object
- .get_page ⇒ Object
- .list_destinations ⇒ Object
Instance Attribute Details
#city ⇒ Object
Returns the value of attribute city.
10 11 12 |
# File 'lib/top_25_travel_destinations/destination.rb', line 10 def city @city end |
#city_description ⇒ Object
Returns the value of attribute city_description.
10 11 12 |
# File 'lib/top_25_travel_destinations/destination.rb', line 10 def city_description @city_description end |
#country ⇒ Object
Returns the value of attribute country.
10 11 12 |
# File 'lib/top_25_travel_destinations/destination.rb', line 10 def country @country end |
#list_destinations ⇒ Object
Returns the value of attribute list_destinations.
10 11 12 |
# File 'lib/top_25_travel_destinations/destination.rb', line 10 def list_destinations @list_destinations end |
#rank ⇒ Object
Returns the value of attribute rank.
10 11 12 |
# File 'lib/top_25_travel_destinations/destination.rb', line 10 def rank @rank end |
Class Method Details
.destination_information(input) ⇒ Object
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 |
# File 'lib/top_25_travel_destinations/destination.rb', line 43 def self.destination_information(input) @get_dest_det ||= self.get_page.css('.tcDest_details') dest = [] get_destinations.css("##{input}").each do |x| dest << x.css('div.tcRank').text dest << x.css('div.tcCity').text dest << x.css('div.tcCountry').text end @get_dest_det.css("#tcDest#{input}_details").each do |d| dest << d.css('div.description p').text.gsub("Learn More >", "") end input = nil until input == "menu" puts "What would you like to know about #{dest[1]}?" puts "rank, country, description, or menu" input = gets.chomp.downcase if input == "rank" puts "----------------------" puts "The rank of #{dest[1]} is: #{dest[0]}" puts "----------------------" elsif input == "country" puts "----------------------" puts "#{dest[1]} is located in #{dest[2]}" puts "----------------------" elsif input == "description" puts "----------------------" puts dest[3] puts "----------------------" elsif input == "menu" list_destinations else puts "Incorrect input, please try again" end end end |
.find_destination_by_name(name) ⇒ Object
12 13 14 |
# File 'lib/top_25_travel_destinations/destination.rb', line 12 def self.find_destination_by_name(name) @@all.detect{|d| d.name == name} end |
.get_destinations ⇒ Object
28 29 30 |
# File 'lib/top_25_travel_destinations/destination.rb', line 28 def self.get_destinations @get_dest ||= self.get_page.css('.tcDest.clickable') end |
.get_page ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/top_25_travel_destinations/destination.rb', line 17 def self.get_page # the first time I call this method, i set an instance # the second time i want to check if that instance variable exists # if yes, return it # else # create @doc ||= Nokogiri::HTML(open("http://www.tripadvisor.com/TravelersChoice-Destinations")) # Memoization - poor man caching end |
.list_destinations ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/top_25_travel_destinations/destination.rb', line 33 def self.list_destinations #lists all the destinations @counter = 1 get_destinations.each do |x| @dest = x.css('div.tcCity').text puts "#{@counter}. #{@dest}" @counter += 1 end end |