Class: Chronicle::ETL::FilterTransformer

Inherits:
Transformer show all
Defined in:
lib/chronicle/etl/transformers/filter_transformer.rb

Overview

Return only records that match all the conditions of the filters setting.

Instance Attribute Summary

Attributes inherited from Transformer

#stashed_records

Attributes included from Registry::SelfRegistering

#connector_registration

Instance Method Summary collapse

Methods inherited from Transformer

#call, #call_finish, #finish, #initialize

Methods included from Registry::SelfRegistering

#register_connector

Methods included from Configurable

included

Constructor Details

This class inherits a constructor from Chronicle::ETL::Transformer

Instance Method Details

#transform(record) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/chronicle/etl/transformers/filter_transformer.rb', line 15

def transform(record)
  record_hash = record.data.to_h

  @config.filters.each do |key, value|
    path = key.split('.').map do |k|
      k.match?(/^\d+$/) ? k.to_i : k.to_sym
    end

    return nil unless record_hash.dig(*path) == value
  end

  record.data
end