diff --git a/app/models/budget/stats.rb b/app/models/budget/stats.rb index c493e5de4..0b1d6d459 100644 --- a/app/models/budget/stats.rb +++ b/app/models/budget/stats.rb @@ -2,13 +2,12 @@ class Budget::Stats include Statisticable alias_method :budget, :resource - def generate - stats = %w[total_participants total_participants_support_phase total_participants_vote_phase - total_budget_investments total_votes total_selected_investments - total_unfeasible_investments total_male_participants total_female_participants - total_supports total_unknown_gender_or_age age_groups male_percentage - female_percentage headings total_participants_web total_participants_booths] - stats.map { |stat_name| [stat_name.to_sym, send(stat_name)] }.to_h + def stats_methods + %w[total_participants total_participants_support_phase total_participants_vote_phase + total_budget_investments total_votes total_selected_investments + total_unfeasible_investments total_male_participants total_female_participants + total_supports total_unknown_gender_or_age age_groups male_percentage + female_percentage headings total_participants_web total_participants_booths] end private diff --git a/app/models/concerns/statisticable.rb b/app/models/concerns/statisticable.rb index 9e3eb4412..db46d88dc 100644 --- a/app/models/concerns/statisticable.rb +++ b/app/models/concerns/statisticable.rb @@ -7,5 +7,9 @@ module Statisticable def initialize(resource) @resource = resource end + + def generate + stats_methods.map { |stat_name| [stat_name.to_sym, send(stat_name)] }.to_h + end end end diff --git a/app/models/poll/stats.rb b/app/models/poll/stats.rb index 35a89c5a6..4b2452545 100644 --- a/app/models/poll/stats.rb +++ b/app/models/poll/stats.rb @@ -3,14 +3,13 @@ class Poll::Stats include StatsHelper alias_method :poll, :resource - def generate - stats = %w[total_participants total_participants_web total_web_valid total_web_white total_web_null - total_participants_booth total_booth_valid total_booth_white total_booth_null - total_valid_votes total_white_votes total_null_votes valid_percentage_web valid_percentage_booth - total_valid_percentage white_percentage_web white_percentage_booth total_white_percentage - null_percentage_web null_percentage_booth total_null_percentage total_participants_web_percentage - total_participants_booth_percentage] - stats.map { |stat_name| [stat_name.to_sym, send(stat_name)] }.to_h + def stats_methods + %w[total_participants total_participants_web total_web_valid total_web_white total_web_null + total_participants_booth total_booth_valid total_booth_white total_booth_null + total_valid_votes total_white_votes total_null_votes valid_percentage_web valid_percentage_booth + total_valid_percentage white_percentage_web white_percentage_booth total_white_percentage + null_percentage_web null_percentage_booth total_null_percentage total_participants_web_percentage + total_participants_booth_percentage] end private