Class: Decidim::StatsPresenter

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
decidim-core/app/presenters/decidim/stats_presenter.rb

Overview

A general presenter to render statistics in participatory spaces.

Instance Method Summary collapse

Instance Method Details

#comments_stats(name) ⇒ Object


6
7
8
9
10
11
12
13
14
15
# File 'decidim-core/app/presenters/decidim/stats_presenter.rb', line 6

def comments_stats(name)
  comments = Decidim.component_manifests.map do |component_manifest|
    component_manifest.stats.only([:comments_count])
                      .filter({ tag: :comments })
                      .with_context(published_components)
                      .map { |_name, value| value }.sum
  end
  comments_count = comments.inject(0, :+) { |sum, value| sum + value }
  [[name, :comments_count, comments_count]]
end

#statistics(grouped_stats) ⇒ Object


17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'decidim-core/app/presenters/decidim/stats_presenter.rb', line 17

def statistics(grouped_stats)
  statistics = []
  grouped_stats.each do |_manifest_name, stats|
    stats.each_with_index.each do |stat, _index|
      stat.each_with_index.map do |_item, subindex|
        next unless (subindex % 3).zero?
        next if stat[subindex + 2].zero?

        statistics << { stat_title: stat[subindex + 1], stat_number: stat[subindex + 2] }
      end
    end
  end
  statistics
end