HabitatMap/AirCasting

View on GitHub
app/services/group_by_stream.rb

Summary

Maintainability
A
0 mins
Test Coverage
class GroupByStream
  def call(measurements:)
    measurements
      .each_with_object({}) do |measurement, acc|
        key = measurement.build_stream
        previous = acc.key?(key) ? acc[key] : []
        acc[key] = previous + [measurement]
      end
      .transform_values { |values| values.sort_by(&:time_with_time_zone) }
  end
end