Class: GAI18n::Content
- Inherits:
-
Object
- Object
- GAI18n::Content
- Defined in:
- lib/gai18n/content.rb
Instance Attribute Summary collapse
-
#current ⇒ Object
readonly
Returns the value of attribute current.
Instance Method Summary collapse
- #deep_merge!(second) ⇒ Object
-
#initialize(raw) ⇒ Content
constructor
A new instance of Content.
- #keys ⇒ Object
- #to_h ⇒ Object
- #value_for(key) ⇒ Object
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
#current ⇒ Object (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 |
#keys ⇒ Object
25 26 27 |
# File 'lib/gai18n/content.rb', line 25 def keys flatten_keys current end |
#to_h ⇒ Object
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 |