Module: Request::GroupingHelpers

Defined in:
app/models/request/grouping_helpers.rb

Overview

rubocop:todo Style/Documentation

Instance Method Summary collapse

Instance Method Details

#group_requests_by_submission_id(requests) ⇒ Object


3
4
5
6
7
8
9
10
# File 'app/models/request/grouping_helpers.rb', line 3

def group_requests_by_submission_id(requests)
  # NOTE: Not using group_by(&:submission_id) to maintain the order of the submissions from the order of the requests
  requests
    .inject(Hash.new { |h, k| h[k] = [] }) do |groups, request|
      groups.tap { groups[request.submission_id] << request }
    end
    .values
end