Class: Realize::Filter::ByKeyValue
- Inherits:
-
Object
- Object
- Realize::Filter::ByKeyValue
- Includes:
- Arrays
- Defined in:
- lib/realize/filter/by_key_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 statically 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:) ⇒ ByKeyValue
constructor
A new instance of ByKeyValue.
- #transform(resolver, value, _time, _record) ⇒ Object
Methods included from Arrays
Constructor Details
#initialize(key:, value:) ⇒ ByKeyValue
Returns a new instance of ByKeyValue.
25 26 27 28 29 30 31 32 |
# File 'lib/realize/filter/by_key_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_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_value.rb', line 19 def value @value end |
Instance Method Details
#transform(resolver, value, _time, _record) ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/realize/filter/by_key_value.rb', line 34 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 |