Module: TimeBucket

Defined in:
lib/time_bucket.rb,
lib/time_bucket/version.rb

Constant Summary collapse

TIME_INTERVALS =
[
  "30 minutes", "1 hour", "3 hours", "6 hours", "12 hours", "1 day"
]
VERSION =
"0.0.1"

Class Method Summary collapse

Class Method Details

.bucket_from_seconds(seconds) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/time_bucket.rb', line 10

def self.bucket_from_seconds(seconds)
  bucket = TIME_INTERVALS.detect do |interval|
    time_interval, time_units = interval.split(' ')
    seconds.floor <= (Time.now - time_interval.to_i.send(time_units).ago).to_i
  end
  bucket || "longer than #{TIME_INTERVALS.last}"
end