Module: Forecast::Adapter

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



16
17
18
# File 'lib/forecast/adapter.rb', line 16

def self.included(base)
  base.extend(ClassMethods)
end

.instanceObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/forecast/adapter.rb', line 20

def self.instance
  options = {}
  provider = Forecast.config.provider
  if provider.is_a?(String) || provider.is_a?(Symbol)
    adapter_name = provider.to_sym
  elsif provider.is_a?(Hash)
    adapter_name = provider[:adapter].to_s
    options = provider.clone
    options.delete('adapter')
  end
  if adapter_name
    if Forecast.config.adapters != nil && Forecast.config.adapters.has_key?(adapter_name)
      options = options.merge(Forecast.config.adapters[adapter_name])
    end
    adapter_classname = (adapter_name.to_s << "_adapter").split('_').collect!{ |w| w.capitalize }.join
    adapter_class = Object.const_get('Forecast').const_get("Adapters").const_get(adapter_classname)
    adapter_class.new(options)
  else 
    puts 'Adapter not found'
  end
end

Instance Method Details

#current(latitude, longitude) ⇒ Object



47
48
# File 'lib/forecast/adapter.rb', line 47

def current(latitude, longitude)
end

#daily(latitude, longitude) ⇒ Object



53
54
# File 'lib/forecast/adapter.rb', line 53

def daily(latitude, longitude)
end

#hourly(latitude, longitude) ⇒ Object



50
51
# File 'lib/forecast/adapter.rb', line 50

def hourly(latitude, longitude)
end

#initialize(options = {}) ⇒ Object



42
43
44
45
# File 'lib/forecast/adapter.rb', line 42

def initialize(options = {})
  @options = ({cache: Forecast.config.cache}).merge(options)
  @http = Http.new({cache: @options[:cache]})
end