Class: Globalize::Locale::Fallbacks

Inherits:
Hash
  • Object
show all
Defined in:
lib/globalize/locale/fallbacks.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*defaults) ⇒ Fallbacks

Returns a new instance of Fallbacks.



22
23
24
25
26
27
28
# File 'lib/globalize/locale/fallbacks.rb', line 22

def initialize(*defaults)
  @map = {}
  map defaults.pop if defaults.last.is_a?(Hash)
  
  defaults = [I18n.default_locale.to_sym] if defaults.empty?
  self.defaults = defaults 
end

Instance Attribute Details

#defaultsObject

Returns the value of attribute defaults.



33
34
35
# File 'lib/globalize/locale/fallbacks.rb', line 33

def defaults
  @defaults
end

Instance Method Details

#[](tag) ⇒ Object



35
36
37
38
# File 'lib/globalize/locale/fallbacks.rb', line 35

def [](tag)
  tag = tag.to_sym
  has_key?(tag) ? fetch(tag) : store(tag, compute(tag))
end

#map(mappings) ⇒ Object



40
41
42
43
44
45
46
47
48
# File 'lib/globalize/locale/fallbacks.rb', line 40

def map(mappings)
  mappings.each do |from, to|
    from, to = from.to_sym, Array(to)
    to.each do |to|
      @map[from] ||= []
      @map[from] << to.to_sym
    end
  end
end