Class: Chronicle::ETL::SortTransformer

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

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, #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

#finishObject



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/chronicle/etl/transformers/sort_transformer.rb', line 18

def finish
  return unless @stashed_records&.any?

  sorted = @stashed_records.sort_by do |record|
    value = record.data[@config.key]
    value.nil? ? [1] : [0, value]
  end

  sorted.reverse! if @config.direction == 'desc'
  sorted
end

#transform(record) ⇒ Object



14
15
16
# File 'lib/chronicle/etl/transformers/sort_transformer.rb', line 14

def transform(record)
  stash_record(record)
end