Skip to content

Instantly share code, notes, and snippets.

@brynary
Created September 15, 2011 15:14
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 brynary/1219515 to your computer and use it in GitHub Desktop.
Save brynary/1219515 to your computer and use it in GitHub Desktop.
%h4 Utility Account Summary
%table.data-table
= @user_metrics.utility_accounts_summary.each_count do |name, count|
%tr
%th= name
%td= count
class UtilityAccountSummary
def initialize(scope)
@scope = scope
end
def each_count
yield "Online Open", online_open_accounts.count
yield "Online Closed", online_closed_accounts.count
yield "Offline Open", offline_open_accounts.count
yield "Offline Closed", offline_closed_accounts.count
end
private
def online_open_accounts
online_accounts.where(:closed => false)
end
def online_closed_accounts
online_accounts.where(:closed => true)
end
def offline_open_accounts
offline_accounts.where(:closed => false)
end
def offline_closed_accounts
offline_accounts.where(:closed => true)
end
def offline_accounts
@scope.where(:user_id => nil)
end
def online_accounts
@scope.where("user_id IS NOT NULL")
end
end
@akahn
Copy link

akahn commented Sep 15, 2011

It's always irked me that there's no way to do IS NOT NULL with a hash like all the rest. Not that I mind SQL, but just the inconsistency of it.

@jacqui
Copy link

jacqui commented Sep 22, 2011

That's irked me too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment