Centralize some match-type-dependent logic.

This commit is contained in:
Patrick Fairbank
2019-07-20 22:42:56 -07:00
parent 016fcc907b
commit 02fa6954bd
6 changed files with 41 additions and 32 deletions

View File

@@ -104,6 +104,15 @@ func (match *Match) CapitalizedType() string {
return strings.ToUpper(match.Type[0:1]) + match.Type[1:]
}
func (match *Match) TypePrefix() string {
if match.Type == "practice" {
return "P"
} else if match.Type == "qualification" {
return "Q"
}
return ""
}
func (match *Match) TbaCode() string {
if match.Type == "qualification" {
return fmt.Sprintf("qm%s", match.DisplayName)
@@ -113,3 +122,23 @@ func (match *Match) TbaCode() string {
}
return ""
}
// Returns true if the match is of a type that allows substitution of teams.
func (match *Match) ShouldAllowSubstitution() bool {
return match.Type != "qualification"
}
// Returns true if the red and yellow cards should be updated as a result of the match.
func (match *Match) ShouldUpdateCards() bool {
return match.Type == "qualification" || match.Type == "elimination"
}
// Returns true if the rankings should be updated as a result of the match.
func (match *Match) ShouldUpdateRankings() bool {
return match.Type == "qualification"
}
// Returns true if the elimination match set should be updated as a result of the match.
func (match *Match) ShouldUpdateEliminationMatches() bool {
return match.Type == "elimination"
}