Class: WeatherChecker
- Inherits:
-
Object
- Object
- WeatherChecker
- Defined in:
- lib/weather_checker.rb
Class Attribute Summary collapse
-
.cache ⇒ Object
Returns the value of attribute cache.
-
.cache_time ⇒ Object
Returns the value of attribute cache_time.
Instance Attribute Summary collapse
-
#weather ⇒ Object
Returns the value of attribute weather.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(weather_obj) ⇒ WeatherChecker
constructor
A new instance of WeatherChecker.
- #rain_chance? ⇒ Boolean
- #temperature_above?(celsius_degrees) ⇒ Boolean
- #temperature_below?(celsius_degrees) ⇒ Boolean
Constructor Details
#initialize(weather_obj) ⇒ WeatherChecker
Returns a new instance of WeatherChecker.
18 19 20 |
# File 'lib/weather_checker.rb', line 18 def initialize weather_obj @weather = weather_obj end |
Class Attribute Details
.cache ⇒ Object
Returns the value of attribute cache.
8 9 10 |
# File 'lib/weather_checker.rb', line 8 def cache @cache end |
.cache_time ⇒ Object
Returns the value of attribute cache_time.
8 9 10 |
# File 'lib/weather_checker.rb', line 8 def cache_time @cache_time end |
Instance Attribute Details
#weather ⇒ Object
Returns the value of attribute weather.
16 17 18 |
# File 'lib/weather_checker.rb', line 16 def weather @weather end |
Class Method Details
.for(location) ⇒ Object
40 41 42 43 44 45 |
# File 'lib/weather_checker.rb', line 40 def self.for(location) = WeatherChecker.get(location) || Barometer.new(location) weather = .measure WeatherChecker.set(location, ) WeatherChecker.new weather end |
Instance Method Details
#rain_chance? ⇒ Boolean
30 31 32 33 34 35 36 37 38 |
# File 'lib/weather_checker.rb', line 30 def rain_chance? icons = weather.sources.map { |s| class_name = "Barometer::WeatherService::#{s.to_s.gsub(/(^.|_.)/) { |x| x.gsub(/_/,'').upcase }}" klass = class_name.split('::').inject(Kernel) { |scope, const_name| scope.const_get(const_name) } klass._wet_icon_codes }.flatten return weather.current.wet? icons end |
#temperature_above?(celsius_degrees) ⇒ Boolean
26 27 28 |
# File 'lib/weather_checker.rb', line 26 def temperature_above? celsius_degrees return celsius_degrees.to_i < weather.current.temperature.c end |
#temperature_below?(celsius_degrees) ⇒ Boolean
22 23 24 |
# File 'lib/weather_checker.rb', line 22 def temperature_below? celsius_degrees return celsius_degrees.to_i > weather.current.temperature.c end |