Class: Realize::Filter::ByKeyValuePresence
- Inherits:
-
Object
- Object
- Realize::Filter::ByKeyValuePresence
- 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
-
#key ⇒ Object
readonly
Returns the value of attribute key.
Instance Method Summary collapse
-
#initialize(key:) ⇒ ByKeyValuePresence
constructor
A new instance of ByKeyValuePresence.
- #transform(resolver, value, _time, _record) ⇒ Object
Methods included from Arrays
Constructor Details
#initialize(key:) ⇒ ByKeyValuePresence
Returns a new instance of ByKeyValuePresence.
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
#key ⇒ Object (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 |