Class: Forecast::Config

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/forecast/config.rb', line 7

def initialize
  
  @config_file = nil 
  @provider||= :open_weather_map
  self.load(File.dirname(__FILE__) + '/**/*.yml')
  
  def theme
    if @theme != nil 
      if @theme.is_a?(Hash)
        return @theme
      end
      if themes[@theme] != nil
        return themes[@theme]
      end
    end
    return @theme
  end
end

Instance Attribute Details

#adaptersObject

Returns the value of attribute adapters.



5
6
7
# File 'lib/forecast/config.rb', line 5

def adapters
  @adapters
end

#cacheObject

Returns the value of attribute cache.



5
6
7
# File 'lib/forecast/config.rb', line 5

def cache
  @cache
end

#conditionsObject

Returns the value of attribute conditions.



5
6
7
# File 'lib/forecast/config.rb', line 5

def conditions
  @conditions
end

#config_fileObject

Returns the value of attribute config_file.



5
6
7
# File 'lib/forecast/config.rb', line 5

def config_file
  @config_file
end

#providerObject

Returns the value of attribute provider.



5
6
7
# File 'lib/forecast/config.rb', line 5

def provider
  @provider
end

#scaleObject

Returns the value of attribute scale.



5
6
7
# File 'lib/forecast/config.rb', line 5

def scale
  @scale
end

#synonymsObject

Returns the value of attribute synonyms.



5
6
7
# File 'lib/forecast/config.rb', line 5

def synonyms
  @synonyms
end

#themeObject

Returns the value of attribute theme.



5
6
7
# File 'lib/forecast/config.rb', line 5

def theme
  @theme
end

#themesObject

Returns the value of attribute themes.



5
6
7
# File 'lib/forecast/config.rb', line 5

def themes
  @themes
end

Instance Method Details

#load(pattern) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/forecast/config.rb', line 27

def load(pattern)
  Dir.glob(pattern).sort{ |a, b| a.split(/\//).length <=> b.split(/\//).length}.reverse.each do |f|
    obj = YAML.load_file(f)
    # puts 'load forecast config ' + f.to_s
    if obj['forecast'] != nil
      obj['forecast'].each do |k, v|
        if respond_to?("#{k}")
          o = send("#{k}")
          if v.is_a?(Hash) && o.is_a?(Hash)
            v = deep_merge(o, v)
          end
        end
        send("#{k}=", v) if respond_to?("#{k}=")
      end
    end
  end
end