Class: Decidim::Results::ResultStatsCalculator
- Inherits:
-
Object
- Object
- Decidim::Results::ResultStatsCalculator
- Defined in:
- decidim-results/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.
9 10 11 |
# File 'decidim-results/app/services/decidim/results/result_stats_calculator.rb', line 9 def initialize(result) @result = result end |
Instance Method Details
#attendees_count ⇒ Object
26 27 28 |
# File 'decidim-results/app/services/decidim/results/result_stats_calculator.rb', line 26 def attendees_count meetings.where("attendees_count > 0").sum(:attendees_count) end |
#comments_count ⇒ Object
22 23 24 |
# File 'decidim-results/app/services/decidim/results/result_stats_calculator.rb', line 22 def comments_count Decidim::Comments::Comment.where(root_commentable: proposals).count end |
#contributions_count ⇒ Object
30 31 32 |
# File 'decidim-results/app/services/decidim/results/result_stats_calculator.rb', line 30 def contributions_count meetings.where("contributions_count > 0").sum(:contributions_count) end |
#meetings_count ⇒ Object
34 35 36 |
# File 'decidim-results/app/services/decidim/results/result_stats_calculator.rb', line 34 def meetings_count meetings.count end |
#proposals_count ⇒ Object
13 14 15 |
# File 'decidim-results/app/services/decidim/results/result_stats_calculator.rb', line 13 def proposals_count proposals.count end |
#votes_count ⇒ Object
17 18 19 20 |
# File 'decidim-results/app/services/decidim/results/result_stats_calculator.rb', line 17 def votes_count return 0 unless proposals proposals.sum { |proposal| proposal.votes.size } end |