Module: AggtiveRecord::EggScopes::Collation::ClassMethods
- Defined in:
- lib/aggtive_record/egg_scopes/collation.rb
Instance Method Summary collapse
- #earliest_time_of(records) ⇒ Object
-
#enumerable_asc_sort(records) ⇒ Object
Public: a helper sorts the records after ActiveRecord query, ascending.
- #latest_time_of(records) ⇒ Object
-
#timespan_of(records) ⇒ Object
Public: records: An ActiveRecord collection.
- #timespan_to_now(records) ⇒ Object
Instance Method Details
#earliest_time_of(records) ⇒ Object
20 21 22 |
# 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) ⇒ Object
Public: a helper sorts the records after ActiveRecord query, ascending
Returns a mapped array of timestamps
16 17 18 |
# 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) ⇒ Object
24 25 26 |
# File 'lib/aggtive_record/egg_scopes/collation.rb', line 24 def latest_time_of(records) enumerable_asc_sort(records).last end |
#timespan_of(records) ⇒ Object
Public:
records: An ActiveRecord collection
Returns the number of seconds TODO - eliminate use of helper methods
33 34 35 |
# 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) ⇒ Object
37 38 39 40 |
# 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 |