Class: RailsOrbit::TimeRange

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_orbit/time_range.rb

Constant Summary collapse

OPTIONS =
{
  "1h"  => { minutes: 60,    bucket_minutes: 1,  delta_window: 15.minutes, label: "1h" },
  "6h"  => { minutes: 360,   bucket_minutes: 5,  delta_window: 1.hour,     label: "6h" },
  "24h" => { minutes: 1440,  bucket_minutes: 15, delta_window: 1.hour,     label: "24h" },
  "7d"  => { minutes: 10080, bucket_minutes: 60, delta_window: 6.hours,    label: "7d" },
  "30d" => { minutes: 43200, bucket_minutes: 360, delta_window: 1.day,     label: "30d" },
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(param) ⇒ TimeRange

Returns a new instance of TimeRange.



13
14
15
# File 'lib/rails_orbit/time_range.rb', line 13

def initialize(param)
  @key = OPTIONS.key?(param) ? param : "24h"
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



11
12
13
# File 'lib/rails_orbit/time_range.rb', line 11

def key
  @key
end

Instance Method Details

#bucket_minutesObject



21
22
23
# File 'lib/rails_orbit/time_range.rb', line 21

def bucket_minutes
  config[:bucket_minutes]
end

#delta_windowObject



25
26
27
# File 'lib/rails_orbit/time_range.rb', line 25

def delta_window
  config[:delta_window]
end

#labelObject



29
30
31
# File 'lib/rails_orbit/time_range.rb', line 29

def label
  config[:label]
end

#sinceObject



17
18
19
# File 'lib/rails_orbit/time_range.rb', line 17

def since
  config[:minutes].minutes.ago
end