Class: Woody::Decorators::Insights::Hydrator

Inherits:
Object
  • Object
show all
Defined in:
lib/woody/decorators/insights/hydrator.rb

Class Method Summary collapse

Class Method Details

.hydrate(yml_config, data) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/woody/decorators/insights/hydrator.rb', line 7

def self.hydrate(yml_config, data)
  yml_config.map do |config_node|
    raw_value = data.dig(*config_node['json_location'])

    if config_node.key?('transformers')
      config_node['value'] = transform(
        config_node['transformers'], raw_value
      )
      config_node.delete('transformers')
    else
      config_node['value'] = raw_value
    end

    config_node.delete('json_location')
    config_node
  end
end

.hydrate_array(yml_config, data_array) ⇒ Object



25
26
27
28
29
30
# File 'lib/woody/decorators/insights/hydrator.rb', line 25

def self.hydrate_array(yml_config, data_array)
  data_array.map do |data|
    yml_config_copy = Marshal.load(Marshal.dump(yml_config))
    hydrate(yml_config_copy, data)
  end
end

.transform(*args) ⇒ Object



32
33
34
# File 'lib/woody/decorators/insights/hydrator.rb', line 32

def self.transform(*args)
  FieldTransformer.apply(*args)
end