Class: Forecast
- Inherits:
-
Object
show all
- Defined in:
- lib/forecast.rb,
lib/forecast/http.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/forecast_io_adapter.rb,
lib/forecast/adapters/wunderground_adapter.rb,
lib/forecast/adapters/open_weather_map_adapter.rb
Defined Under Namespace
Modules: Adapter, Adapters, Utils
Classes: Collection, Config, Http
Constant Summary
collapse
- PROVIDERS =
Dir.glob(File.expand_path(File.dirname(__FILE__) + '/forecast/adapters/*.*')).map{ |f| File.basename(f, '_adapter.rb') }
- VERSION =
"0.0.9"
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(attrs = {}) ⇒ Forecast
Returns a new instance of Forecast.
21
22
23
|
# File 'lib/forecast.rb', line 21
def initialize(attrs = {})
@source = OpenStruct.new(attrs)
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
17
18
19
|
# File 'lib/forecast.rb', line 17
def method_missing(method, *args, &block)
@source.send(method, *args, &block)
end
|
Class Method Details
.config ⇒ Object
61
62
63
|
# File 'lib/forecast/config.rb', line 61
def self.config
@@config ||= Config.new
end
|
65
66
67
68
69
70
71
|
# File 'lib/forecast/config.rb', line 65
def self.configure
yield self.config
if self.config.config_file != nil
self.config.load(self.config.config_file)
end
end
|
.current(latitude, longitude) ⇒ Object
51
52
53
|
# File 'lib/forecast.rb', line 51
def current(latitude, longitude)
return adapter.current(latitude, longitude)
end
|
.daily(latitude, longitude) ⇒ Object
59
60
61
|
# File 'lib/forecast.rb', line 59
def daily(latitude, longitude)
return adapter.daily(latitude, longitude)
end
|
.hourly(latitude, longitude) ⇒ Object
55
56
57
|
# File 'lib/forecast.rb', line 55
def hourly(latitude, longitude)
return adapter.hourly(latitude, longitude)
end
|
Instance Method Details
#as_json(options = nil) ⇒ Object
25
26
27
|
# File 'lib/forecast.rb', line 25
def as_json(options = nil)
@source.table.as_json(options)
end
|
#icon ⇒ Object
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/forecast.rb', line 33
def icon
if self.condition != nil && Forecast.config.theme.is_a?(Hash)
icon_prefix = Forecast.config.theme.has_key?('prefix') ? Forecast.config.theme['prefix'] : ''
icon_suffix = Forecast.config.theme.has_key?('suffix') ? Forecast.config.theme['suffix'] : ''
icon_name = Forecast.config.theme['conditions'].has_key?(self.condition) ? Forecast.config.theme['conditions'][self.condition] : self.condition
icon_name = icon_name.to_s.gsub(/(.)([A-Z])/,'\1-\2').gsub(/\s*/, '').downcase
icon = icon_prefix + icon_name + icon_suffix
return icon != nil ? icon : self.icon
end
self.condition.is_a?(String) && self.condition.downcase.strip.gsub(' ', '-').gsub(/[^\w-]/, '')
end
|
#to_json(*a) ⇒ Object
29
30
31
|
# File 'lib/forecast.rb', line 29
def to_json *a
self.marshal_dump.to_json a
end
|