Class: TravelInspiration::Theme
- Inherits:
-
Object
- Object
- TravelInspiration::Theme
- Defined in:
- lib/travel_inspiration/themes.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#url ⇒ Object
Returns the value of attribute url.
Class Method Summary collapse
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
6 7 8 |
# File 'lib/travel_inspiration/themes.rb', line 6 def name @name end |
#url ⇒ Object
Returns the value of attribute url.
6 7 8 |
# File 'lib/travel_inspiration/themes.rb', line 6 def url @url end |
Class Method Details
.list_theme_names ⇒ Object
8 9 10 |
# File 'lib/travel_inspiration/themes.rb', line 8 def self.list_theme_names self.scrape_themes end |
.scrape_themes ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# 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) ⇒ Object
27 28 29 |
# 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 |