Class: SciolyFF::Validator::Subdivisions
Overview
Checks for one subdivision in the Subdivisions section of a SciolyFF file
Constant Summary
collapse
- REQUIRED =
{
name: String
}.freeze
- OPTIONAL =
{
medals: Integer,
trophies: Integer,
'maximum place': Integer
}.freeze
Instance Method Summary
collapse
Methods included from Sections
#all_required_sections?, #no_extra_sections?, #rep_is_hash?, #sections_are_correct_type?
Methods inherited from Checker
inherited, #send
Constructor Details
Returns a new instance of Subdivisions.
22
23
24
25
|
# 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
|
Instance Method Details
#matching_teams?(subdivision, logger) ⇒ Boolean
33
34
35
36
37
38
|
# 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) ⇒ Boolean
42
43
44
45
|
# 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) ⇒ Boolean
47
48
49
50
|
# 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) ⇒ Boolean
52
53
54
|
# 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) ⇒ Boolean
27
28
29
30
31
|
# 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
|