Class: GAI18n::Content

Inherits:
Object
  • Object
show all
Defined in:
lib/gai18n/content.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw) ⇒ Content

Returns a new instance of Content.



5
6
7
# File 'lib/gai18n/content.rb', line 5

def initialize(raw)
  @current = raw
end

Instance Attribute Details

#currentObject (readonly)

Returns the value of attribute current.



3
4
5
# File 'lib/gai18n/content.rb', line 3

def current
  @current
end

Instance Method Details

#deep_merge!(second) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/gai18n/content.rb', line 9

def deep_merge!(second)
  merger = proc do |key, v1, v2|
    if Hash === v1 && Hash === v2
      v1.merge!(v2, &merger)
    else
      v2
    end
  end
  current.merge!(second, &merger)
  self
end

#keysObject



25
26
27
# File 'lib/gai18n/content.rb', line 25

def keys
  flatten_keys current
end

#to_hObject



21
22
23
# File 'lib/gai18n/content.rb', line 21

def to_h
  current
end

#value_for(key) ⇒ Object



29
30
31
32
33
34
# File 'lib/gai18n/content.rb', line 29

def value_for(key)
  keys = key.split('.')
  keys.inject(current) do |hash, key|
    hash[key]
  end
end