Class: TravelInspiration::Country
- Inherits:
-
Object
- Object
- TravelInspiration::Country
- Defined in:
- lib/travel_inspiration/country.rb
Instance Attribute Summary collapse
-
#best_visit_season ⇒ Object
Returns the value of attribute best_visit_season.
-
#details ⇒ Object
Returns the value of attribute details.
-
#high_season ⇒ Object
Returns the value of attribute high_season.
-
#low_season ⇒ Object
Returns the value of attribute low_season.
-
#name ⇒ Object
Returns the value of attribute name.
-
#summary_quote ⇒ Object
Returns the value of attribute summary_quote.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
- #country_info ⇒ Object
-
#initialize(name) ⇒ Country
constructor
A new instance of Country.
-
#scrape_info ⇒ Object
scrape country information.
-
#scrape_season ⇒ Object
scrape best time to visit from Country/weather website.
Constructor Details
#initialize(name) ⇒ Country
Returns a new instance of Country.
10 11 12 |
# File 'lib/travel_inspiration/country.rb', line 10 def initialize(name) @name = name end |
Instance Attribute Details
#best_visit_season ⇒ Object
Returns the value of attribute best_visit_season.
8 9 10 |
# File 'lib/travel_inspiration/country.rb', line 8 def best_visit_season @best_visit_season end |
#details ⇒ Object
Returns the value of attribute details.
8 9 10 |
# File 'lib/travel_inspiration/country.rb', line 8 def details @details end |
#high_season ⇒ Object
Returns the value of attribute high_season.
8 9 10 |
# File 'lib/travel_inspiration/country.rb', line 8 def high_season @high_season end |
#low_season ⇒ Object
Returns the value of attribute low_season.
8 9 10 |
# File 'lib/travel_inspiration/country.rb', line 8 def low_season @low_season end |
#name ⇒ Object
Returns the value of attribute name.
8 9 10 |
# File 'lib/travel_inspiration/country.rb', line 8 def name @name end |
#summary_quote ⇒ Object
Returns the value of attribute summary_quote.
8 9 10 |
# File 'lib/travel_inspiration/country.rb', line 8 def summary_quote @summary_quote end |
#url ⇒ Object
Returns the value of attribute url.
8 9 10 |
# File 'lib/travel_inspiration/country.rb', line 8 def url @url end |
Instance Method Details
#country_info ⇒ Object
14 15 16 17 18 19 20 21 22 23 |
# 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 ⇒ Object
scrape country information
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# 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 ⇒ Object
scrape best time to visit from Country/weather website
49 50 51 52 53 54 55 56 57 58 59 60 61 |
# 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 |