Class: Realize::Filter::ByKeyRecordValue
- Inherits:
-
Object
- Object
- Realize::Filter::ByKeyRecordValue
- Includes:
- Arrays
- Defined in:
- lib/realize/filter/by_key_record_value.rb
Overview
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.
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#value ⇒ Object
(also: #desired_value)
readonly
Returns the value of attribute value.
Instance Method Summary collapse
-
#initialize(key:, value:) ⇒ ByKeyRecordValue
constructor
A new instance of ByKeyRecordValue.
- #transform(resolver, value, _time, original_record) ⇒ Object
Methods included from Arrays
Constructor Details
#initialize(key:, value:) ⇒ ByKeyRecordValue
Returns a new instance of ByKeyRecordValue.
25 26 27 28 29 30 31 32 |
# 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 |
Instance Attribute Details
#key ⇒ Object (readonly)
Returns the value of attribute key.
19 20 21 |
# File 'lib/realize/filter/by_key_record_value.rb', line 19 def key @key end |
#value ⇒ Object (readonly) Also known as: desired_value
Returns the value of attribute value.
19 20 21 |
# File 'lib/realize/filter/by_key_record_value.rb', line 19 def value @value end |
Instance Method Details
#transform(resolver, value, _time, original_record) ⇒ Object
34 35 36 37 38 39 40 41 |
# 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 |