Class: Decidim::Results::ResultStatsCalculator

Inherits:
Object
  • Object
show all
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

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_countObject



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_countObject



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_countObject



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_countObject



34
35
36
# File 'decidim-results/app/services/decidim/results/result_stats_calculator.rb', line 34

def meetings_count
  meetings.count
end

#proposals_countObject



13
14
15
# File 'decidim-results/app/services/decidim/results/result_stats_calculator.rb', line 13

def proposals_count
  proposals.count
end

#votes_countObject



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