Class: C11n::Conversion::ComposedKeyDeserializer

Inherits:
Object
  • Object
show all
Defined in:
lib/c11n/conversion/composed_key_deserializer.rb

Overview

Deserializes translations in tabular form into Hash.

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#tableObject

Returns the value of attribute table.



7
8
9
# File 'lib/c11n/conversion/composed_key_deserializer.rb', line 7

def table
  @table
end

#translationsObject (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

#deserializeObject



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