From 0e916b3ff9c66477b87902567dddfb8bc5538a0f Mon Sep 17 00:00:00 2001 From: Malaber <32635600+Malaber@users.noreply.github.com> Date: Mon, 13 May 2019 13:57:23 +0200 Subject: [PATCH] Actually make singleton_methods private (Rubocop told me so and I trust the police) --- app/services/playoff_stage_service.rb | 62 ++++++++++++++------------- 1 file changed, 32 insertions(+), 30 deletions(-) diff --git a/app/services/playoff_stage_service.rb b/app/services/playoff_stage_service.rb index 8cd5bc3..f6beb54 100644 --- a/app/services/playoff_stage_service.rb +++ b/app/services/playoff_stage_service.rb @@ -101,38 +101,40 @@ class PlayoffStageService match_below end - private + class << self + private - def self.find_companion_match(current_position, current_stage) - companion_match_position = current_position.even? ? current_position + 1 : current_position - 1 - current_stage.matches.find { |m| m.position == companion_match_position } - end - - def self.assign_correct_match_scores!(match_scores, winners) - case match_scores.size - when 0 - # when 0 match_scores are already there we create both of them with the respective winner from above - match_scores = winners.map { |winner| MatchScore.new(team: winner) } - when 1 - # when 1 match_score is present, we need to check which team is contained within and add the other team as well - if match_scores.first.team == winners.first - match_scores.push MatchScore.new(team: winners.second) - elsif match_scores.first.team == winners.second - match_scores.push MatchScore.new(team: winners.first) - else - match_scores.first.destroy - match_scores = winners.map { |winner| MatchScore.new(team: winner) } - end - when 2 - # when 2 match_scores are present, the teams just get overwritten - match_scores.first.team = winners.first - match_scores.second.team = winners.second + def find_companion_match(current_position, current_stage) + companion_match_position = current_position.even? ? current_position + 1 : current_position - 1 + current_stage.matches.find { |m| m.position == companion_match_position } end - match_scores - end - def self.get_winners_of(companion_match, current_match) - matches = [current_match, companion_match].sort_by(&:position) - matches.map(&:winner) + def assign_correct_match_scores!(match_scores, winners) + case match_scores.size + when 0 + # when 0 match_scores are already there we create both of them with the respective winner from above + match_scores = winners.map { |winner| MatchScore.new(team: winner) } + when 1 + # when 1 match_score is present, we need to check which team is contained within and add the other team as well + if match_scores.first.team == winners.first + match_scores.push MatchScore.new(team: winners.second) + elsif match_scores.first.team == winners.second + match_scores.push MatchScore.new(team: winners.first) + else + match_scores.first.destroy + match_scores = winners.map { |winner| MatchScore.new(team: winner) } + end + when 2 + # when 2 match_scores are present, the teams just get overwritten + match_scores.first.team = winners.first + match_scores.second.team = winners.second + end + match_scores + end + + def get_winners_of(companion_match, current_match) + matches = [current_match, companion_match].sort_by(&:position) + matches.map(&:winner) + end end end