public
Created

  • Download Gist
gistfile1.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
class Message < ActiveRecord::Base
scope :last_two_weeks, -> {
where(:created_at => (2.weeks.ago..Time.now))
}
scope :for_month, (date) -> {
where(:created_at => (date.beginning_of_month..date.end_of_month))
}
def self.sum_word_count
sum(:word_count)
end
end
 
dan.messages.for_month(2.months.ago).sum_word_count
 
dan.messages.last_two_weeks.sum_word_count
 
dan.messages.sum_word_count

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.