Class: Decidim::Elections::Admin::VotesForStatistics
- Inherits:
-
Query
- Object
- Query
- Decidim::Elections::Admin::VotesForStatistics
- Defined in:
- app/queries/decidim/elections/admin/votes_for_statistics.rb
Overview
A class used to find election votes for statistics
Class Method Summary collapse
-
.for(election) ⇒ Object
Syntactic sugar to initialize the class and return the queried object.
Instance Method Summary collapse
-
#initialize(election) ⇒ VotesForStatistics
constructor
A new instance of VotesForStatistics.
-
#query ⇒ Object
Finds the votes for an election which get count for the statistics.
Constructor Details
#initialize(election) ⇒ VotesForStatistics
Returns a new instance of VotesForStatistics.
13 14 15 |
# File 'app/queries/decidim/elections/admin/votes_for_statistics.rb', line 13 def initialize(election) @election = election end |
Class Method Details
.for(election) ⇒ Object
Syntactic sugar to initialize the class and return the queried object.
9 10 11 |
# File 'app/queries/decidim/elections/admin/votes_for_statistics.rb', line 9 def self.for(election) new(election).query end |
Instance Method Details
#query ⇒ Object
Finds the votes for an election which get count for the statistics
18 19 20 |
# File 'app/queries/decidim/elections/admin/votes_for_statistics.rb', line 18 def query @election.votes.accepted.pick(Arel.sql("COUNT(id)"), Arel.sql("COUNT(distinct voter_id)")) end |