Class: Decidim::Elections::Admin::VotesForStatistics

Inherits:
Rectify::Query
  • Object
show all
Defined in:
decidim-elections/app/queries/decidim/elections/admin/votes_for_statistics.rb

Overview

A class used to find election votes for statistics

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(election) ⇒ VotesForStatistics

Returns a new instance of VotesForStatistics.


13
14
15
# File 'decidim-elections/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 'decidim-elections/app/queries/decidim/elections/admin/votes_for_statistics.rb', line 9

def self.for(election)
  new(election).query
end

Instance Method Details

#queryObject

Finds the votes for an election which get count for the statistics


18
19
20
# File 'decidim-elections/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