Module: DependentsHelper
- Included in:
- DependentsSerializer
- Defined in:
- app/serializers/dependents_serializer.rb
Instance Method Summary collapse
- #current_and_pending_decisions(diaries) ⇒ Object
- #dependency_decisions(diaries) ⇒ Object
- #dependent_benefit_types(decisions) ⇒ Object
- #in_future(decision) ⇒ Object
- #max_time(a, b) ⇒ Object
- #still_pending(decision, award_event_id) ⇒ Object
- #trim_whitespace(str) ⇒ Object
- #upcoming_removals(decisions) ⇒ Object
Instance Method Details
#current_and_pending_decisions(diaries) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'app/serializers/dependents_serializer.rb', line 38 def current_and_pending_decisions(diaries) # Filter by eligible minor child or school attendance types and if they are the current or future decisions decisions = dependency_decisions(diaries) .filter do |dec| (START_EVENTS.include?(dec[:dependency_decision_type]) && !in_future(dec)) || (END_EVENTS.include?(dec[:dependency_decision_type]) && in_future(dec)) end decisions.group_by { |dec| dec[:person_id] } .transform_values do |decs| # get only most recent active decision and add back to array active = decs.filter do |dec| START_EVENTS.include?(dec[:dependency_decision_type]) && decs.any? { |d| still_pending(d, dec[:award_event_id]) } end most_recent = active.max { |a, b| max_time(a, b) } # include all future events (including school attendance begins) (decs.filter { |dec| FUTURE_EVENTS.include?(dec[:dependency_decision_type]) && in_future(dec) } + [most_recent]).compact end end |
#dependency_decisions(diaries) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 |
# File 'app/serializers/dependents_serializer.rb', line 62 def dependency_decisions(diaries) decisions = if diaries.is_a?(Hash) diaries[:dependency_decs] else Rails.logger.warn('Diaries is not a hash! Diaries value: ', diaries) nil end return if decisions.nil? decisions.is_a?(Hash) ? [decisions] : decisions end |
#dependent_benefit_types(decisions) ⇒ Object
31 32 33 34 35 36 |
# File 'app/serializers/dependents_serializer.rb', line 31 def dependent_benefit_types(decisions) decisions.transform_values do |decs| dec = decs.find { |d| START_EVENTS.include?(d[:dependency_decision_type]) } dec && trim_whitespace(dec[:dependency_status_type_description]) end end |
#in_future(decision) ⇒ Object
13 14 15 |
# File 'app/serializers/dependents_serializer.rb', line 13 def in_future(decision) Time.zone.parse(decision[:award_effective_date].to_s) > Time.zone.now end |
#max_time(a, b) ⇒ Object
9 10 11 |
# File 'app/serializers/dependents_serializer.rb', line 9 def max_time(a, b) a[:award_effective_date] <=> b[:award_effective_date] end |
#still_pending(decision, award_event_id) ⇒ Object
17 18 19 |
# File 'app/serializers/dependents_serializer.rb', line 17 def still_pending(decision, award_event_id) decision[:award_event_id] == award_event_id && in_future(decision) end |
#trim_whitespace(str) ⇒ Object
21 22 23 |
# File 'app/serializers/dependents_serializer.rb', line 21 def trim_whitespace(str) str&.gsub(/\s+/, ' ') end |
#upcoming_removals(decisions) ⇒ Object
25 26 27 28 29 |
# File 'app/serializers/dependents_serializer.rb', line 25 def upcoming_removals(decisions) decisions.transform_values do |decs| decs.filter { |dec| END_EVENTS.include?(dec[:dependency_decision_type]) }.max { |a, b| max_time(a, b) } end end |