Class: C11n::Conversion::ComposedKeyDeserializer
- Inherits:
-
Object
- Object
- C11n::Conversion::ComposedKeyDeserializer
- Defined in:
- lib/c11n/conversion/composed_key_deserializer.rb
Overview
Deserializes translations in tabular form into Hash.
Instance Attribute Summary collapse
-
#table ⇒ Object
Returns the value of attribute table.
-
#translations ⇒ Object
readonly
Returns the value of attribute translations.
Instance Method Summary collapse
- #create_or_get_leaf_node_for(path) ⇒ Object
- #deserialize ⇒ Object
-
#initialize(table) ⇒ ComposedKeyDeserializer
constructor
A new instance of ComposedKeyDeserializer.
Constructor Details
#initialize(table) ⇒ ComposedKeyDeserializer
Returns a new instance of ComposedKeyDeserializer.
10 11 12 13 |
# File 'lib/c11n/conversion/composed_key_deserializer.rb', line 10 def initialize(table) @table = table @translations = {} end |
Instance Attribute Details
#table ⇒ Object
Returns the value of attribute table.
7 8 9 |
# File 'lib/c11n/conversion/composed_key_deserializer.rb', line 7 def table @table end |
#translations ⇒ Object (readonly)
Returns the value of attribute translations.
8 9 10 |
# File 'lib/c11n/conversion/composed_key_deserializer.rb', line 8 def translations @translations end |
Instance Method Details
#create_or_get_leaf_node_for(path) ⇒ Object
24 25 26 27 28 |
# File 'lib/c11n/conversion/composed_key_deserializer.rb', line 24 def create_or_get_leaf_node_for(path) path[0..-2].inject(@translations) do |node, path_component| node[path_component] ||= {} end end |
#deserialize ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/c11n/conversion/composed_key_deserializer.rb', line 15 def deserialize @table.each do |composed_key, value| path = path_for(composed_key) create_or_get_leaf_node_for(path)[path.last] = value end @translations end |