Class: SciolyFF::Validator::Teams
Overview
Checks for one team in the Teams section of a SciolyFF file
Constant Summary
collapse
- REQUIRED =
{
number: Integer,
school: String,
state: String
}.freeze
- OPTIONAL =
{
'school abbreviation': String,
subdivision: String,
suffix: String,
city: String,
disqualified: [true, false],
exhibition: [true, false]
}.freeze
Instance Method Summary
collapse
Methods included from Sections
#all_required_sections?, #no_extra_sections?, #sections_are_correct_type?
Methods inherited from Checker
#send
Constructor Details
#initialize(rep) ⇒ Teams
Returns a new instance of Teams.
26
27
28
29
30
|
# File 'lib/sciolyff/validator/teams.rb', line 26
def initialize(rep)
initialize_teams_info(rep[:Teams])
@placings = rep[:Placings].group_by { |p| p[:team] }
@exempt = rep[:Tournament][:'exempt placings'] || 0
end
|
Instance Method Details
#correct_number_of_exempt_placings?(team, logger) ⇒ Boolean
59
60
61
62
63
64
65
|
# File 'lib/sciolyff/validator/teams.rb', line 59
def correct_number_of_exempt_placings?(team, logger)
count = @placings[team[:number]].count { |p| p[:exempt] }
return true if count == @exempt || team[:exhibition]
logger.error "'team: #{team[:number]}' has incorrect number of "\
"exempt placings (#{count} insteand of #{@exempt})"
end
|
#in_a_subdivision_if_possible?(team, logger) ⇒ Boolean
67
68
69
70
71
|
# File 'lib/sciolyff/validator/teams.rb', line 67
def in_a_subdivision_if_possible?(team, logger)
return true unless @subdivisions && !team[:subdivision]
logger.warn "missing subdivision for 'team: #{team[:number]}'"
end
|
#unambiguous_cities_per_school?(team, logger) ⇒ Boolean
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/sciolyff/validator/teams.rb', line 48
def unambiguous_cities_per_school?(team, logger)
return true unless @schools.keys.find do |other|
team[:city].nil? && !other[1].nil? &&
team[:school] == other[0] &&
team[:state] == other[2]
end
logger.error "city for team number #{team[:number]} is ambiguous, "\
'value is required for unambiguity'
end
|
#unique_number?(team, logger) ⇒ Boolean
32
33
34
35
36
|
# File 'lib/sciolyff/validator/teams.rb', line 32
def unique_number?(team, logger)
return true if @numbers.count(team[:number]) == 1
logger.error "duplicate team number: #{team[:number]}"
end
|
#unique_suffix_per_school?(team, logger) ⇒ Boolean
38
39
40
41
42
43
44
45
46
|
# File 'lib/sciolyff/validator/teams.rb', line 38
def unique_suffix_per_school?(team, logger)
full_school = [team[:school], team[:city], team[:state]]
return true if @schools[full_school].count do |other|
!other[:suffix].nil? && other[:suffix] == team[:suffix]
end <= 1
logger.error "team number #{team[:number]} has the same suffix "\
'as another team from the same school'
end
|