From 37b63cace29a1f9b778086046fd12e185d523762 Mon Sep 17 00:00:00 2001 From: Thor77 Date: Tue, 14 May 2019 22:26:57 +0200 Subject: [PATCH] Use methods instead of attributes because each attribute is only used once and updating a Stage should reflect those changes --- app/services/statistics_service.rb | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/app/services/statistics_service.rb b/app/services/statistics_service.rb index 62ae754..22f302f 100644 --- a/app/services/statistics_service.rb +++ b/app/services/statistics_service.rb @@ -5,15 +5,19 @@ class StatisticsService raise 'Unsupported stage type' if stage.nil? || stage.groups.empty? @stage = stage - @group_scores = sort_group_scores(@stage.groups, :group_points) - - @most_dominant_score = sort_group_scores(@stage.groups, :scored_points).first - @least_dominant_score = sort_group_scores(@stage.groups, :received_points).first end - attr_reader :group_scores - attr_reader :most_dominant_score - attr_reader :least_dominant_score + def group_scores + sort_group_scores(@stage.groups, :group_points) + end + + def most_dominant_score + sort_group_scores(@stage.groups, :scored_points).first + end + + def least_dominant_score + sort_group_scores(@stage.groups, :received_points).first + end private