Skip to content

Instantly share code, notes, and snippets.

@barmstrong
Created November 20, 2010 22:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save barmstrong/708224 to your computer and use it in GitHub Desktop.
Save barmstrong/708224 to your computer and use it in GitHub Desktop.
def self.days_of_week time_ago
days = Hash.new(0)
Transaction.find_each(:conditions => ["created_at > ?", time_ago]) do |t|
days[t.created_at.strftime('%A')] += 1 if t == t.user.transactions.first(:order => 'created_at')
end
puts days.sort{|a,b| b[1]<=>a[1]}.inspect
end
# [["Saturday", 44], ["Sunday", 62], ["Friday", 69], ["Monday", 80], ["Thursday", 93], ["Tuesday", 110], ["Wednesday", 115]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment