Sha256: f82102a9918aa82c5a1a7557131c216df5b09ef21ed28c1084fc3f1909107b96
Contents?: true
Size: 927 Bytes
Versions: 11
Compression:
Stored size: 927 Bytes
Contents
# frozen_string_literal: true module Realize class Filter # This transformer can take an array or a hash (put in array) and it understands how to # select only the records where a key's value statically equates to the transformer's # value. class ByKeyValue include Arrays acts_as_hashable attr_reader :key, :value # value is also passed into #transform so we need to alias it so its not shadowed by # the argument. alias desired_value value def initialize(key:, value:) raise ArgumentError, 'key is required' if key.to_s.empty? @key = key @value = value freeze end def transform(resolver, value, _time, _record) records = array(value) records.select do |record| record_value = resolver.get(record, key) record_value == desired_value end end end end end
Version data entries
11 entries across 11 versions & 1 rubygems