class TravelInspiration::Country
Attributes
best_visit_season[RW]
details[RW]
high_season[RW]
low_season[RW]
name[RW]
summary_quote[RW]
url[RW]
Public Class Methods
new(name)
click to toggle source
# File lib/travel_inspiration/country.rb, line 10 def initialize(name) @name = name end
Public Instance Methods
country_info()
click to toggle source
# File lib/travel_inspiration/country.rb, line 14 def country_info scrape_season #set seasonality information scrape_info #set country name, summary_quote and details puts "\t#{@best_visit_season}! #{@high_season} #{@low_season}\n" puts "\n#{@summary_quote}".blue.bold puts @details end
scrape_info()
click to toggle source
scrape country information
# File lib/travel_inspiration/country.rb, line 26 def scrape_info doc = Nokogiri::HTML(open(url)) info_url = doc.search("#introduction article.love-letter a").attr("href").text info_page = Nokogiri::HTML(open(info_url)) @summary_quote = info_page.search("div.copy--body p.copy--feature").text subtitles = info_page.search("div.copy--body h2").to_a subtitles = subtitles.map {|s| s.text} descriptions = info_page.search("div.copy--body p.copy--body").to_a descriptions = descriptions.map {|d| d.text} descriptions.reject!{|item| item.downcase.end_with?("writer") } @details = subtitles.map.with_index{|title, index| "\n" + title.upcase.red + "\n" + descriptions[index] + "\n" } end
scrape_season()
click to toggle source
scrape best time to visit from Country/weather website
# File lib/travel_inspiration/country.rb, line 49 def scrape_season doc = Nokogiri::HTML(open(url)) seasonality_url = doc.search("#survival-guide ul li:nth-child(2) a").attr("href").text #get country weather url weather_pg = Nokogiri::HTML(open(seasonality_url)) #get high, low, and best time to visit information @high_season = weather_pg.search("div.card--page__content p:nth-child(1)").text @low_season = weather_pg.search("div.card--page__content p:nth-child(5)").first.text shoulder_season = weather_pg.search("div.card--page__content p:nth-child(3)").first.text @best_visit_season = "Best time to visit " + shoulder_season[16..-1] end