class Forecast::Config

Attributes

adapters[RW]
cache[RW]
conditions[RW]
config_file[RW]
provider[RW]
scale[RW]
synonyms[RW]
theme[RW]
themes[RW]

Public Class Methods

new() click to toggle source
# 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

Public Instance Methods

load(pattern) click to toggle source
# 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

Private Instance Methods

deep_merge(hash, other_hash, &block) click to toggle source
# File lib/forecast/config.rb, line 47
def deep_merge(hash, other_hash, &block)
  other_hash.each_pair do |k,v|
    tv = hash[k]
    if tv.is_a?(Hash) && v.is_a?(Hash)
      hash[k] = deep_merge(tv, v, &block)
    else
      hash[k] = block && tv ? block.call(k, tv, v) : v
    end
  end
  hash
end