class TravelInspiration::Theme
Attributes
name[RW]
url[RW]
Public Class Methods
list_theme_names()
click to toggle source
# File lib/travel_inspiration/themes.rb, line 8 def self.list_theme_names self.scrape_themes end
scrape_themes()
click to toggle source
# File lib/travel_inspiration/themes.rb, line 12 def self.scrape_themes themes_list = [] doc = Nokogiri::HTML(open("https://www.lonelyplanet.com/")) themes = doc.search('div.slick-track a.slick-slide') #selects carousel slides themes.each_with_index{|theme, index| if index < 12 then new_theme = TravelInspiration::Theme.new #create theme instance new_theme.name = theme.css("p").text #assign theme name new_theme.url = theme.attr("href") #assign theme url for destination #scraping themes_list[index] = new_theme end } themes_list end
url_for_theme_name(theme_name)
click to toggle source
# File lib/travel_inspiration/themes.rb, line 27 def self.url_for_theme_name(theme_name) "https://www.lonelyplanet.com/#{theme_name.downcase.gsub!(/[\s,]+/,"-")}/" end