Class: TravelInspiration::Destination
- Inherits:
-
Object
- Object
- TravelInspiration::Destination
- Defined in:
- lib/travel_inspiration/destinations.rb
Instance Attribute Summary collapse
-
#continent ⇒ Object
Returns the value of attribute continent.
-
#name ⇒ Object
Returns the value of attribute name.
-
#url ⇒ Object
Returns the value of attribute url.
Class Method Summary collapse
- .list_destination_names(theme_name) ⇒ Object
-
.scrape_destinations(theme_name) ⇒ Object
scrape data using URL.
Instance Attribute Details
#continent ⇒ Object
Returns the value of attribute continent.
6 7 8 |
# File 'lib/travel_inspiration/destinations.rb', line 6 def continent @continent end |
#name ⇒ Object
Returns the value of attribute name.
6 7 8 |
# File 'lib/travel_inspiration/destinations.rb', line 6 def name @name end |
#url ⇒ Object
Returns the value of attribute url.
6 7 8 |
# File 'lib/travel_inspiration/destinations.rb', line 6 def url @url end |
Class Method Details
.list_destination_names(theme_name) ⇒ Object
8 9 10 |
# File 'lib/travel_inspiration/destinations.rb', line 8 def self.list_destination_names(theme_name) self.scrape_destinations(theme_name) end |
.scrape_destinations(theme_name) ⇒ Object
scrape data using URL
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/travel_inspiration/destinations.rb', line 13 def self.scrape_destinations(theme_name) list = [] url = TravelInspiration::Theme.url_for_theme_name(theme_name) doc = Nokogiri::HTML(open(url)) destinations = doc.search('div.SightsList-wrap a') #selects 6 destinations destinations.map.with_index{ |destination, index| new_destination = TravelInspiration::Destination.new #create destination instance new_destination.name = destination.css('h5').text new_destination.continent = destination.css('p').text new_destination.url = destination.attr("href") list[index] = new_destination } list.sort_by! {|obj| [obj.continent, obj.name]} list end |