Class: Cldr::Data::Base

Inherits:
Hash
  • Object
show all
Defined in:
lib/cldr/data/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Hash

#deep_merge, #deep_stringify_keys, #symbolize_keys

Constructor Details

#initialize(*args) ⇒ Base

Returns a new instance of Base.



10
11
12
13
# File 'lib/cldr/data/base.rb', line 10

def initialize(*args)
  hash    = args.last.is_a?(Hash) ? args.pop : {}
  @locale = args.pop.to_sym unless args.empty?
end

Instance Attribute Details

#localeObject (readonly)

Returns the value of attribute locale.



8
9
10
# File 'lib/cldr/data/base.rb', line 8

def locale
  @locale
end

Instance Method Details

#[]=(keys, value) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/cldr/data/base.rb', line 15

def []=(keys, value)
  return if value.nil? || value.respond_to?(:empty?) && value.empty?

  keys = keys.to_s.split('.')
  last_key = keys.pop.to_sym

  target = keys.inject(self) { |target, key| target[key.to_sym] || target.store(key.to_sym, {}) }
  target.store(last_key, value)
end

#update(hash) ⇒ Object



25
26
27
# File 'lib/cldr/data/base.rb', line 25

def update(hash)
  hash.each { |key, value| self[key] = value }
end