Class: Decidim::Accountability::ResultStatsCalculator

Inherits:
Object
  • Object
show all
Defined in:
decidim-accountability/app/services/decidim/accountability/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.


10
11
12
# File 'decidim-accountability/app/services/decidim/accountability/result_stats_calculator.rb', line 10

def initialize(result)
  @result = result
end

Instance Method Details

#attendees_countObject


26
27
28
# File 'decidim-accountability/app/services/decidim/accountability/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-accountability/app/services/decidim/accountability/result_stats_calculator.rb', line 22

def comments_count
  proposals.sum(:comments_count)
end

#contributions_countObject


30
31
32
# File 'decidim-accountability/app/services/decidim/accountability/result_stats_calculator.rb', line 30

def contributions_count
  meetings.where("contributions_count > 0").sum(:contributions_count)
end

#votes_countObject


16
17
18
19
20
# File 'decidim-accountability/app/services/decidim/accountability/result_stats_calculator.rb', line 16

def votes_count
  return 0 unless proposals

  proposals.sum { |proposal| proposal.votes.size }
end