Class: Realize::Filter::ByKeyValuePresence

Inherits:
Object
  • Object
show all
Includes:
Arrays
Defined in:
lib/realize/filter/by_key_value_presence.rb

Overview

This transformer can take an object (will be converted to array) or array and will go through each child object and see if the child record has a value for the specified key. If it does then it will select that record.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Arrays

#array

Constructor Details

#initialize(key:) ⇒ ByKeyValuePresence

Returns a new instance of ByKeyValuePresence.

Raises:

  • (ArgumentError)


21
22
23
24
25
26
27
# File 'lib/realize/filter/by_key_value_presence.rb', line 21

def initialize(key:)
  raise ArgumentError, 'key is required' if key.to_s.empty?

  @key = key

  freeze
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



19
20
21
# File 'lib/realize/filter/by_key_value_presence.rb', line 19

def key
  @key
end

Instance Method Details

#transform(resolver, value, _time, _record) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/realize/filter/by_key_value_presence.rb', line 29

def transform(resolver, value, _time, _record)
  records = array(value)

  records.reject do |record|
    resolver.get(record, key).to_s.empty?
  end
end