Class: Regentanz::GoogleWeather
- Inherits:
-
Object
- Object
- Regentanz::GoogleWeather
- Defined in:
- lib/regentanz/google_weather.rb
Constant Summary
Constants included from Callbacks
Instance Attribute Summary collapse
-
#cache ⇒ Object
readonly
Returns the value of attribute cache.
-
#cache_id ⇒ Object
Returns the value of attribute cache_id.
-
#current ⇒ Object
readonly
Returns the value of attribute current.
-
#forecast ⇒ Object
readonly
Returns the value of attribute forecast.
-
#lang ⇒ Object
Returns the value of attribute lang.
-
#location ⇒ Object
Returns the value of attribute location.
-
#parser ⇒ Object
readonly
Returns the value of attribute parser.
-
#xml ⇒ Object
readonly
Returns the value of attribute xml.
Instance Method Summary collapse
-
#get_weather! ⇒ Object
Loads weather data from known data sources (ie. cache or external API).
-
#initialize(*args) ⇒ GoogleWeather
constructor
Creates an object and queries the weather API.
-
#present? ⇒ Boolean
Provide an accessor to see if we actually got weather info at all.
- #sunrise ⇒ Object
- #sunset ⇒ Object
- #waiting_for_retry? ⇒ Boolean
Methods included from Callbacks
Constructor Details
#initialize(*args) ⇒ GoogleWeather
Creates an object and queries the weather API.
Parameters
-
options
A hash
Available options
-
location
String to pass to Google’s weather API (mandatory) -
cache_id
enables caching with a unique identifier to locate a cached file -
geodata
a hash with keys :lat and :lng, required for sunset/-rise calculations -
lang
Desired language for the returned results (Defaults to “de”)
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/regentanz/google_weather.rb', line 23 def initialize(*args) = args. @options = .symbolize_keys @parser = Parser::GoogleWeather.new self.location = args.first || [:location] self.lang = [:lang] # Activate caching if Regentanz.configuration.cache_backend @cache = Regentanz.configuration.cache_backend.new if Regentanz.configuration.cache_backend @cache_id = [:cache_id] || Regentanz.configuration.cache_backend.sanitize_key(@location) end @geodata = [:geodata] if [:geodata] and [:geodata][:lat] and [:geodata][:lng] get_weather() unless Regentanz.configuration.do_not_get_weather end |
Instance Attribute Details
#cache ⇒ Object (readonly)
Returns the value of attribute cache.
11 12 13 |
# File 'lib/regentanz/google_weather.rb', line 11 def cache @cache end |
#cache_id ⇒ Object
Returns the value of attribute cache_id.
10 11 12 |
# File 'lib/regentanz/google_weather.rb', line 10 def cache_id @cache_id end |
#current ⇒ Object (readonly)
Returns the value of attribute current.
11 12 13 |
# File 'lib/regentanz/google_weather.rb', line 11 def current @current end |
#forecast ⇒ Object (readonly)
Returns the value of attribute forecast.
11 12 13 |
# File 'lib/regentanz/google_weather.rb', line 11 def forecast @forecast end |
#lang ⇒ Object
Returns the value of attribute lang.
11 12 13 |
# File 'lib/regentanz/google_weather.rb', line 11 def lang @lang end |
#location ⇒ Object
Returns the value of attribute location.
10 11 12 |
# File 'lib/regentanz/google_weather.rb', line 10 def location @location end |
#parser ⇒ Object (readonly)
Returns the value of attribute parser.
11 12 13 |
# File 'lib/regentanz/google_weather.rb', line 11 def parser @parser end |
#xml ⇒ Object (readonly)
Returns the value of attribute xml.
11 12 13 |
# File 'lib/regentanz/google_weather.rb', line 11 def xml @xml end |
Instance Method Details
#get_weather! ⇒ Object
Loads weather data from known data sources (ie. cache or external API)
41 |
# File 'lib/regentanz/google_weather.rb', line 41 def get_weather!; get_weather(); end |
#present? ⇒ Boolean
Provide an accessor to see if we actually got weather info at all.
49 50 51 |
# File 'lib/regentanz/google_weather.rb', line 49 def present? current.present? or forecast.present? end |
#sunrise ⇒ Object
53 54 55 |
# File 'lib/regentanz/google_weather.rb', line 53 def sunrise @sunrise ||= @geodata.blank? ? nil : sun_rise_set(:sunrise, @geodata[:lat], @geodata[:lng]) end |
#sunset ⇒ Object
57 58 59 |
# File 'lib/regentanz/google_weather.rb', line 57 def sunset @sunset ||= @geodata.blank? ? nil : sun_rise_set(:sunset, @geodata[:lat], @geodata[:lng]) end |
#waiting_for_retry? ⇒ Boolean
61 62 63 |
# File 'lib/regentanz/google_weather.rb', line 61 def waiting_for_retry? @cache && @cache.waiting_for_retry? end |