Skip to content

Instantly share code, notes, and snippets.

@alexbartlow
Created June 9, 2013 21:39

Revisions

  1. alexbartlow created this gist Jun 9, 2013.
    19 changes: 19 additions & 0 deletions gistfile1.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,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