From 5c6c496d74839ea61dcce6ce205dc26ce89d895e Mon Sep 17 00:00:00 2001 From: Malaber <32635600+Malaber@users.noreply.github.com> Date: Thu, 9 May 2019 09:09:54 +0200 Subject: [PATCH] Add evaluate winner method --- app/models/match.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/models/match.rb b/app/models/match.rb index 8007619..19edf02 100644 --- a/app/models/match.rb +++ b/app/models/match.rb @@ -21,6 +21,13 @@ class Match < ApplicationRecord private + def evaluate_winner + return nil unless finished? + return nil if match_scores.first.points == match_scores.second.points + + match_scores.max_by(&:points).team + end + def stage_xor_group errors.add(:stage_xor_group, 'Stage and Group missing or both present') unless stage.present? ^ group.present? end