Class: Decidim::Results::ResultStatsCalculator
- Inherits:
-
Object
- Object
- Decidim::Results::ResultStatsCalculator
- Defined in:
- app/services/decidim/results/result_stats_calculator.rb
Overview
This class handles statistics of results. Needs a ‘result` in order to find the stats.
Instance Method Summary collapse
- #attendees_count ⇒ Object
- #comments_count ⇒ Object
- #contributions_count ⇒ Object
-
#initialize(result) ⇒ ResultStatsCalculator
constructor
Public: Initializes the service.
- #meetings_count ⇒ Object
- #proposals_count ⇒ Object
- #votes_count ⇒ Object
Constructor Details
#initialize(result) ⇒ ResultStatsCalculator
Public: Initializes the service. result - The result from which to calculate the stats.
10 11 12 |
# File 'app/services/decidim/results/result_stats_calculator.rb', line 10 def initialize(result) @result = result end |
Instance Method Details
#attendees_count ⇒ Object
27 28 29 |
# File 'app/services/decidim/results/result_stats_calculator.rb', line 27 def attendees_count meetings.where("attendees_count > 0").sum(:attendees_count) end |
#comments_count ⇒ Object
23 24 25 |
# File 'app/services/decidim/results/result_stats_calculator.rb', line 23 def comments_count Decidim::Comments::Comment.where(root_commentable: proposals).count end |
#contributions_count ⇒ Object
31 32 33 |
# File 'app/services/decidim/results/result_stats_calculator.rb', line 31 def contributions_count meetings.where("contributions_count > 0").sum(:contributions_count) end |
#meetings_count ⇒ Object
35 36 37 |
# File 'app/services/decidim/results/result_stats_calculator.rb', line 35 def meetings_count meetings.count end |
#proposals_count ⇒ Object
14 15 16 |
# File 'app/services/decidim/results/result_stats_calculator.rb', line 14 def proposals_count proposals.count end |
#votes_count ⇒ Object
18 19 20 21 |
# File 'app/services/decidim/results/result_stats_calculator.rb', line 18 def votes_count return 0 unless proposals proposals.sum { |proposal| proposal.votes.size } end |