Class: Forecast

Inherits:
Object
  • Object
show all
Includes:
Model
Defined in:
lib/forecast.rb,
lib/forecast/cache.rb,
lib/forecast/model.rb,
lib/forecast/utils.rb,
lib/forecast/config.rb,
lib/forecast/adapter.rb,
lib/forecast/version.rb,
lib/forecast/collection.rb,
lib/forecast/adapters/yahoo_adapter.rb,
lib/forecast/adapters/wunderground_adapter.rb,
lib/forecast/adapters/open_weather_map_adapter.rb

Defined Under Namespace

Modules: Adapter, Adapters, Model, Utils Classes: Cache, Collection, Config

Constant Summary collapse

VERSION =
"0.0.3"

Instance Attribute Summary collapse

Class Method Summary collapse

Methods included from Model

#as_json, #from_json, #icon, included, #initialize, #to_json

Instance Attribute Details

#conditionObject

Returns the value of attribute condition.



18
19
20
# File 'lib/forecast.rb', line 18

def condition
  @condition
end

#dateObject

Returns the value of attribute date.



18
19
20
# File 'lib/forecast.rb', line 18

def date
  @date
end

#latitudeObject

Returns the value of attribute latitude.



18
19
20
# File 'lib/forecast.rb', line 18

def latitude
  @latitude
end

#longitudeObject

Returns the value of attribute longitude.



18
19
20
# File 'lib/forecast.rb', line 18

def longitude
  @longitude
end

#orig_conditionObject

Returns the value of attribute orig_condition.



18
19
20
# File 'lib/forecast.rb', line 18

def orig_condition
  @orig_condition
end

#tempObject

Returns the value of attribute temp.



18
19
20
# File 'lib/forecast.rb', line 18

def temp
  @temp
end

#temp_maxObject

Returns the value of attribute temp_max.



18
19
20
# File 'lib/forecast.rb', line 18

def temp_max
  @temp_max
end

#temp_minObject

Returns the value of attribute temp_min.



18
19
20
# File 'lib/forecast.rb', line 18

def temp_min
  @temp_min
end

Class Method Details

.configObject



61
62
63
# File 'lib/forecast/config.rb', line 61

def self.config
  @@config ||= Config.new
end

.configure {|self.config| ... } ⇒ Object

Yields:



65
66
67
68
69
70
71
72
# File 'lib/forecast/config.rb', line 65

def self.configure
  yield self.config
  # puts 'configured'
  # if self.config.config_file != nil
    # puts 'load config from file'
    # self.config.load(@config_file)
  # end
end

.current(latitude, longitude) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/forecast.rb', line 23

def current(latitude, longitude)
  cache_key = "current:#{latitude},#{longitude}"
  forecast = read_cache(cache_key)
  if forecast == nil
    forecast = adapter.current(latitude, longitude)
    write_cache(cache_key, forecast)
  end
  return forecast
end

.daily(latitude, longitude) ⇒ Object



43
44
45
46
47
48
49
50
51
# File 'lib/forecast.rb', line 43

def daily(latitude, longitude)
  cache_key = "daily:#{latitude},#{longitude}"
  forecasts = read_cache(cache_key)
  if forecasts == nil
    forecasts = adapter.daily(latitude, longitude)
    write_cache(cache_key, forecasts)
  end
  return forecasts
end

.hourly(latitude, longitude) ⇒ Object



33
34
35
36
37
38
39
40
41
# File 'lib/forecast.rb', line 33

def hourly(latitude, longitude)
  cache_key = "hourly:#{latitude},#{longitude}"
  forecasts = read_cache(cache_key)
  if forecasts == nil
    forecasts = adapter.hourly(latitude, longitude)
    write_cache(cache_key, forecasts)
  end
  return forecasts
end