Class: Realize::Filter::Inactive
- Inherits:
-
Object
- Object
- Realize::Filter::Inactive
- Includes:
- Arrays
- Defined in:
- lib/realize/filter/inactive.rb
Overview
This transformer can take in an array or hash (put in an array) and filters out the objects who have a start date greater than today or end date less than today. If a start or end date is null then it is assumed to be infinity.
Constant Summary collapse
- DEFAULT_START_DATE_KEY =
'start_date'
- DEFAULT_END_DATE_KEY =
'end_date'
Instance Attribute Summary collapse
-
#end_date_key ⇒ Object
readonly
Returns the value of attribute end_date_key.
-
#start_date_key ⇒ Object
readonly
Returns the value of attribute start_date_key.
Instance Method Summary collapse
-
#initialize(start_date_key: DEFAULT_START_DATE_KEY, end_date_key: DEFAULT_END_DATE_KEY) ⇒ Inactive
constructor
A new instance of Inactive.
- #transform(resolver, value, time, _record) ⇒ Object
Methods included from Arrays
Constructor Details
#initialize(start_date_key: DEFAULT_START_DATE_KEY, end_date_key: DEFAULT_END_DATE_KEY) ⇒ Inactive
Returns a new instance of Inactive.
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/realize/filter/inactive.rb', line 24 def initialize( start_date_key: DEFAULT_START_DATE_KEY, end_date_key: DEFAULT_END_DATE_KEY ) raise ArgumentError, 'start_date_key is required' if start_date_key.to_s.empty? raise ArgumentError, 'end_date_key is required' if end_date_key.to_s.empty? @start_date_key = start_date_key @end_date_key = end_date_key freeze end |
Instance Attribute Details
#end_date_key ⇒ Object (readonly)
Returns the value of attribute end_date_key.
22 23 24 |
# File 'lib/realize/filter/inactive.rb', line 22 def end_date_key @end_date_key end |
#start_date_key ⇒ Object (readonly)
Returns the value of attribute start_date_key.
22 23 24 |
# File 'lib/realize/filter/inactive.rb', line 22 def start_date_key @start_date_key end |
Instance Method Details
#transform(resolver, value, time, _record) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/realize/filter/inactive.rb', line 37 def transform(resolver, value, time, _record) current_time = time.utc records = array(value) records.select do |record| start_time = parse_date(resolver.get(record, start_date_key)) end_time = parse_date(resolver.get(record, end_date_key)) valid?(start_time, end_time, current_time) end end |