class SciolyFF::Validator::Teams
Constants
- OPTIONAL
- REQUIRED
Public Class Methods
new(rep)
click to toggle source
# File lib/sciolyff/validator/teams.rb, line 27 def initialize(rep) initialize_teams_info(rep[:Teams]) @subdivisions = rep[:Subdivisions]&.map { |s| s[:name] } || [] @placings = rep[:Placings].group_by { |p| p[:team] } @exempt = rep[:Tournament][:'exempt placings'] || 0 end
Public Instance Methods
correct_number_of_exempt_placings?(team, logger)
click to toggle source
# File lib/sciolyff/validator/teams.rb, line 69 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)
click to toggle source
# File lib/sciolyff/validator/teams.rb, line 85 def in_a_subdivision_if_possible?(team, logger) return true unless !@subdivisions.empty? && !team[:subdivision] logger.warn "missing subdivision for 'team: #{team[:number]}'" end
in_canonical_list?(team, logger)
click to toggle source
# File lib/sciolyff/validator/teams.rb, line 93 def in_canonical_list?(team, logger) rep = [team[:school], team[:city], team[:state]] return true if canonical?(rep, 'schools.csv', logger) location = rep[1..-1].compact.join ', ' logger.warn "non-canonical school: #{team[:school]} in #{location}" end
matching_subdivision?(team, logger)
click to toggle source
# File lib/sciolyff/validator/teams.rb, line 77 def matching_subdivision?(team, logger) sub = team[:subdivision] return true if sub.nil? || @subdivisions.include?(sub) logger.error "'subdivision: #{sub}' does not match any name in "\ 'section Subdivisions' end
suffix_needed?(team, logger)
click to toggle source
# File lib/sciolyff/validator/teams.rb, line 50 def suffix_needed?(team, logger) rep = [team[:school], team[:city], team[:state]] return true unless team[:suffix] && @schools[rep].count == 1 logger.warn "team number #{team[:number]} may have unnecessary "\ "suffix: #{team[:suffix]}" end
unambiguous_cities_per_school?(team, logger)
click to toggle source
# File lib/sciolyff/validator/teams.rb, line 58 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)
click to toggle source
# File lib/sciolyff/validator/teams.rb, line 34 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)
click to toggle source
# File lib/sciolyff/validator/teams.rb, line 40 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
Private Instance Methods
initialize_teams_info(teams)
click to toggle source
# File lib/sciolyff/validator/teams.rb, line 103 def initialize_teams_info(teams) @numbers = teams.map { |t| t[:number] } @schools = teams.group_by { |t| [t[:school], t[:city], t[:state]] } end