Module: AggtiveRecord::EggScopes::Collation::Rate::ClassMethods

Defined in:
lib/aggtive_record/egg_scopes/collation/rate.rb

Overview

Public: a rate expects that ActiveRelation has a grouping self is a ActiveRecord scope

Instance Method Summary collapse

Instance Method Details

#rate_per(time_period) ⇒ Object

Public

Returns float indicating rate of records per given time period



16
17
18
19
20
21
# File 'lib/aggtive_record/egg_scopes/collation/rate.rb', line 16

def rate_per(time_period)
  time_period_secs = AggtiveRecord::Time.to_seconds(time_period)
  records = self.scoped.to_a

  return records.size.to_f * time_period_secs / self.timespan_to_now(records)
end