class TravelInspiration::Destination

Attributes

continent[RW]
name[RW]
url[RW]

Public Class Methods

list_destination_names(theme_name) click to toggle source
# 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) click to toggle source

scrape data using URL

# 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