Module: Fall::Ext::Enumerable

Included in:
Enumerable
Defined in:
lib/fall/ext/enumerable.rb

Instance Method Summary collapse

Instance Method Details

#window_timestamps(window_size_seconds = 3600) ⇒ Object



4
5
6
7
8
# File 'lib/fall/ext/enumerable.rb', line 4

def window_timestamps(window_size_seconds = 3600)
  group_by { |ts| (ts.to_time.to_i / window_size_seconds) * window_size_seconds }
    .transform_keys { |ts| Time.at(ts) }
    .map { |k, v| { k => v } }
end