Class: WeatherLookup::Weather
- Inherits:
-
Object
- Object
- WeatherLookup::Weather
- Defined in:
- lib/weather_lookup/weather.rb
Instance Attribute Summary collapse
-
#current_temp ⇒ Object
Returns the value of attribute current_temp.
-
#location ⇒ Object
Returns the value of attribute location.
-
#time ⇒ Object
Returns the value of attribute time.
-
#weather ⇒ Object
Returns the value of attribute weather.
-
#zip ⇒ Object
Returns the value of attribute zip.
Class Method Summary collapse
-
.scrape_wunderground(zip) ⇒ Object
private.
Instance Method Summary collapse
-
#initialize(attributes = {}) ⇒ Weather
constructor
A new instance of Weather.
Constructor Details
#initialize(attributes = {}) ⇒ Weather
Returns a new instance of Weather.
7 8 9 10 11 12 13 |
# File 'lib/weather_lookup/weather.rb', line 7 def initialize(attributes = {}) @weather = attributes[:weather] @current_temp = attributes[:current_temp] @location = attributes[:location] @time = attributes[:time] @zip = attributes[:zip] end |
Instance Attribute Details
#current_temp ⇒ Object
Returns the value of attribute current_temp.
5 6 7 |
# File 'lib/weather_lookup/weather.rb', line 5 def current_temp @current_temp end |
#location ⇒ Object
Returns the value of attribute location.
5 6 7 |
# File 'lib/weather_lookup/weather.rb', line 5 def location @location end |
#time ⇒ Object
Returns the value of attribute time.
5 6 7 |
# File 'lib/weather_lookup/weather.rb', line 5 def time @time end |
#weather ⇒ Object
Returns the value of attribute weather.
5 6 7 |
# File 'lib/weather_lookup/weather.rb', line 5 def weather @weather end |
#zip ⇒ Object
Returns the value of attribute zip.
5 6 7 |
# File 'lib/weather_lookup/weather.rb', line 5 def zip @zip end |
Class Method Details
.scrape_wunderground(zip) ⇒ Object
private
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/weather_lookup/weather.rb', line 22 def self.scrape_wunderground(zip) doc = Nokogiri::HTML(open("https://www.wunderground.com/cgi-bin/findweather/getForecast?query=#{zip}")) self.new({ current_temp: /\d{2}(?:.\d)?/.match(doc.search("div.small-6.columns").text).to_s, location: doc.search("h1.city-nav-header").text.split("\n\t\t")[1], weather: doc.search("div#curCond").text, time: doc.search("div.local-time").text.sub(' ', ''), zip: zip }) # temp = doc.search("div.small-6.columns").text # @current_temp = /\d{2}(?:.\d)?/.match(temp).to_s # location = doc.search("h1.city-nav-header").text # @location = location.split("\n\t\t")[1] # weather = doc.search("div#curCond").text # @weather = weather # # time = doc.search("div.local-time").text # time.slice!(0) # @time = time end |