Redo Match status evaluation
This commit is contained in:
parent
9c808b9921
commit
6ff2c8d21e
|
|
@ -1,7 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Match < ApplicationRecord
|
||||
enum state: %i[single_team not_ready not_started in_progress team1_won team2_won undecided]
|
||||
enum state: %i[single_team not_ready not_started in_progress finished undecided]
|
||||
|
||||
belongs_to :stage, optional: true
|
||||
belongs_to :group, optional: true
|
||||
|
|
@ -11,22 +11,24 @@ class Match < ApplicationRecord
|
|||
|
||||
validate :stage_xor_group
|
||||
|
||||
def evaluate_match_result
|
||||
if match_scores.first == match_scores.second
|
||||
if group_match?
|
||||
:undecided
|
||||
else
|
||||
:in_progress
|
||||
end
|
||||
else
|
||||
:finished
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def stage_xor_group
|
||||
errors.add(:stage_xor_group, 'Stage and Group missing or both present') unless stage.present? ^ group.present?
|
||||
end
|
||||
|
||||
def evaluate_status
|
||||
if score_team1 < score_team2
|
||||
:team2_won
|
||||
elsif score_team2 < score_team1
|
||||
:team1_won
|
||||
else
|
||||
group_match? ? :undecided : :in_progress
|
||||
end
|
||||
end
|
||||
|
||||
def group_match?
|
||||
group.present?
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in New Issue