module AggtiveRecord::EggScopes::Collation::ClassMethods
Public Instance Methods
earliest_time_of(records)
click to toggle source
# File lib/aggtive_record/egg_scopes/collation.rb, line 20 def earliest_time_of(records) enumerable_asc_sort(records).first end
enumerable_asc_sort(records)
click to toggle source
Public: a helper sorts the records after ActiveRecord query, ascending
Returns a mapped array of timestamps
# File lib/aggtive_record/egg_scopes/collation.rb, line 16 def enumerable_asc_sort(records) records.map{|r| r.send(self.datetime_attribute)}.sort end
latest_time_of(records)
click to toggle source
# File lib/aggtive_record/egg_scopes/collation.rb, line 24 def latest_time_of(records) enumerable_asc_sort(records).last end
timespan_of(records)
click to toggle source
Public:
records: An ActiveRecord collection
Returns the number of seconds TODO - eliminate use of helper methods
# File lib/aggtive_record/egg_scopes/collation.rb, line 33 def timespan_of(records) latest_time_of(records) - earliest_time_of(records) end
timespan_to_now(records)
click to toggle source
# File lib/aggtive_record/egg_scopes/collation.rb, line 37 def timespan_to_now(records) return 0 if records.empty? || records.nil? ::Time.now - earliest_time_of(records) end