Created
September 15, 2011 15:14
-
-
Save brynary/1219515 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%h4 Utility Account Summary | |
%table.data-table | |
= @user_metrics.utility_accounts_summary.each_count do |name, count| | |
%tr | |
%th= name | |
%td= count |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.