class SciolyFF::Validator::Subdivisions
Checks for one subdivision in the Subdivisions
section of a SciolyFF
file
Constants
- OPTIONAL
- REQUIRED
Public Class Methods
new(rep)
click to toggle source
# File lib/sciolyff/validator/subdivisions.rb, line 22 def initialize(rep) @names = rep[:Subdivisions].map { |s| s[:name] } @teams = rep[:Teams].group_by { |t| t[:subdivision] } end
Public Instance Methods
matching_teams?(subdivision, logger)
click to toggle source
# File lib/sciolyff/validator/subdivisions.rb, line 33 def matching_teams?(subdivision, logger) name = subdivision[:name] return true if @teams[name] logger.error "subdivision with 'name: #{name}' has no teams" end
maximum_place_within_range?(subdivision, logger)
click to toggle source
# File lib/sciolyff/validator/subdivisions.rb, line 42 def maximum_place_within_range?(subdivision, logger) max = team_count(subdivision) within_range?(subdivision, :'maximum place', logger, 1, max) end
medals_within_range?(subdivision, logger)
click to toggle source
# File lib/sciolyff/validator/subdivisions.rb, line 47 def medals_within_range?(subdivision, logger) max = [team_count(subdivision), subdivision[:'maximum place']].compact.min within_range?(subdivision, :medals, logger, 1, max) end
trophies_within_range?(subdivision, logger)
click to toggle source
# File lib/sciolyff/validator/subdivisions.rb, line 52 def trophies_within_range?(subdivision, logger) within_range?(subdivision, :trophies, logger, 1, team_count(subdivision)) end
unique_name?(subdivision, logger)
click to toggle source
# File lib/sciolyff/validator/subdivisions.rb, line 27 def unique_name?(subdivision, logger) return true if @names.count(subdivision[:name]) == 1 logger.error "duplicate subdivision name: #{subdivision[:name]}" end
Private Instance Methods
team_count(subdivision)
click to toggle source
# File lib/sciolyff/validator/subdivisions.rb, line 58 def team_count(subdivision) @teams[subdivision[:name]].count do |t| t[:subdivision] == subdivision[:name] && !t[:exhibition] end end