From 93cea002f97cfc00b85e70f90d0b1a97c23f4f8c Mon Sep 17 00:00:00 2001 From: Malaber <32635600+Malaber@users.noreply.github.com> Date: Mon, 13 May 2019 11:06:34 +0200 Subject: [PATCH] Change the way, existing match_scores are handled --- app/services/playoff_stage_service.rb | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/app/services/playoff_stage_service.rb b/app/services/playoff_stage_service.rb index ce75551..ce86980 100644 --- a/app/services/playoff_stage_service.rb +++ b/app/services/playoff_stage_service.rb @@ -114,18 +114,14 @@ class PlayoffStageService 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 - team = nil - if match_scores.first.team == winners.first - team = winners.second + match_scores.push MatchScore.new(team: winners.second) elsif match_scores.first.team == winners.second - team = winners.first + match_scores.push MatchScore.new(team: winners.first) else - match_scores.first.team = winners.first - team = winners.second + match_scores.first.destroy + match_scores = winners.map { |winner| MatchScore.new(team: winner) } end - - match_scores.concat MatchScore.new(team: team) when 2 # when 2 match_scores are present, the teams just get overwritten match_scores.first.team = winners.first @@ -136,12 +132,6 @@ class PlayoffStageService def self.get_winners_of(companion_match, current_match) matches = [current_match, companion_match].sort_by(&:position) - if companion_match.finished? - matches.map(&:winner) - else - matches.map do |m| - m == current_match ? m.winner : nil - end - end + matches.map(&:winner) end end