class Sundown::Location
Main class to accomodate core-features, saves weather instance once called.
Public Class Methods
new(location)
click to toggle source
# File lib/sundown/location.rb, line 4 def initialize(location) @location = location end
Public Instance Methods
refresh()
click to toggle source
# File lib/sundown/location.rb, line 22 def refresh @weather = nil end
temperature(degree = 'f')
click to toggle source
# File lib/sundown/location.rb, line 8 def temperature(degree = 'f') if degree == 'c' (weather['query']['results']['channel']['item']['condition']['temp'] .to_f - 32) * 0.5556 else weather['query']['results']['channel']['item']['condition']['temp'] .to_f end end
timestamp()
click to toggle source
# File lib/sundown/location.rb, line 18 def timestamp weather['query']['results']['channel']['item']['condition']['date'] end
Private Instance Methods
weather()
click to toggle source
# File lib/sundown/location.rb, line 28 def weather unless @weather domain = "https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20weather.forecast%20where%20woeid%20in%20(select%20woeid%20from%20geo.places(1)%20where%20text%3D%22#{@location}%22)&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys" url = URI.parse(domain) req = Net::HTTP::Get.new(url.request_uri) http = Net::HTTP.new(url.host, url.port) http.use_ssl = true response = http.request(req).body @weather = JSON.parse(response) end @weather end