Class: HashTemplate

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ HashTemplate



4
5
6
# File 'lib/hash_template.rb', line 4

def initialize(data)
  @data = data
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



2
3
4
# File 'lib/hash_template.rb', line 2

def data
  @data
end

Instance Method Details

#map(mapping) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/hash_template.rb', line 8

def map(mapping)
  mapping.each_with_object({}) do |(key, value), result|
    case value
    when Symbol
      result[key] = data[value]
    when String
      result[key] = analyze_strings(value)
    when Hash
      result[key] = map(value)
    when Array
      result[key] = value.map { |hash| map hash }
    end
  end
end