Class: WeatherChecker

Inherits:
Object
  • Object
show all
Defined in:
lib/weather_checker.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

.cacheObject

Returns the value of attribute cache.



8
9
10
# File 'lib/weather_checker.rb', line 8

def cache
  @cache
end

.cache_timeObject

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

#weatherObject

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)
  barometer = WeatherChecker.get(location) || Barometer.new(location)
  weather = barometer.measure
  WeatherChecker.set(location, barometer)
  WeatherChecker.new weather
end

Instance Method Details

#rain_chance?Boolean

Returns:

  • (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

Returns:

  • (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

Returns:

  • (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