class Realize::Filter::ByKeyRecordValue

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 looked up in the original record equates to the transformer's value.

Attributes

desired_value[R]
key[R]
value[R]

Public Class Methods

new(key:, value:) click to toggle source
# File lib/realize/filter/by_key_record_value.rb, line 25
def initialize(key:, value:)
  raise ArgumentError, 'key is required' if key.to_s.empty?

  @key    = key
  @value  = value

  freeze
end

Public Instance Methods

transform(resolver, value, _time, original_record) click to toggle source
# File lib/realize/filter/by_key_record_value.rb, line 34
def transform(resolver, value, _time, original_record)
  records = array(value)

  records.select do |record|
    record_value = resolver.get(record, key)
    record_value == resolver.get(original_record, desired_value)
  end
end