Class: SciolyFF::Validator::Tournament
Overview
Checks for Tournament section of a SciolyFF file
Constant Summary
collapse
- REQUIRED =
{
location: String,
level: %w[Invitational Regionals States Nationals],
division: %w[A B C],
year: Integer,
date: Date
}.freeze
- OPTIONAL =
{
name: String,
state: String,
medals: Integer,
trophies: Integer,
bids: Integer,
'bids per school': Integer,
'short name': String,
'worst placings dropped': Integer,
'exempt placings': Integer,
'maximum place': Integer,
'per-event n': %w[place participation],
'n offset': Integer
}.freeze
Instance Method Summary
collapse
-
#bids_for_regionals_or_states?(tournament, logger) ⇒ Boolean
-
#bids_per_school_positive?(tournament, logger) ⇒ Boolean
-
#bids_per_school_relevant?(tournament, logger) ⇒ Boolean
-
#bids_within_range?(tournament, logger) ⇒ Boolean
-
#initialize(rep) ⇒ Tournament
constructor
A new instance of Tournament.
-
#maximum_place_within_range?(tournament, logger) ⇒ Boolean
-
#medals_within_range?(tournament, logger) ⇒ Boolean
-
#name_for_not_states_or_nationals?(tournament, logger) ⇒ Boolean
-
#short_name_is_relevant?(tournament, logger) ⇒ Boolean
-
#short_name_is_short?(tournament, logger) ⇒ Boolean
-
#state_for_not_nationals?(tournament, logger) ⇒ Boolean
-
#trophies_within_range?(tournament, logger) ⇒ Boolean
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 Tournament.
35
36
37
38
39
40
|
# File 'lib/sciolyff/validator/tournament.rb', line 35
def initialize(rep)
@maximum_place = rep[:Teams].count { |t| !t[:exhibition] }
@schools_count = rep[:Teams].uniq do |t|
[t[:school], t[:city], t[:state]]
end.count
end
|
Instance Method Details
#bids_for_regionals_or_states?(tournament, logger) ⇒ Boolean
57
58
59
60
61
62
63
64
65
66
67
68
69
|
# File 'lib/sciolyff/validator/tournament.rb', line 57
def bids_for_regionals_or_states?(tournament, logger)
level = tournament[:level]
if %w[Regionals States].include?(level)
return true if tournament.key? :bids
logger.error "field 'bids:' required for level: #{level}"
else
return true unless tournament.key? :bids
logger.error "bids: does not make sense for level: #{level}"
end
end
|
#bids_per_school_positive?(tournament, logger) ⇒ Boolean
71
72
73
74
75
76
|
# File 'lib/sciolyff/validator/tournament.rb', line 71
def bids_per_school_positive?(tournament, logger)
bids = tournament[:'bids per school']
return true if bids.nil? || tournament[:'bids per school'].positive?
logger.error "'bids per school: #{bids}' is not positive"
end
|
#bids_per_school_relevant?(tournament, logger) ⇒ Boolean
78
79
80
81
82
83
|
# File 'lib/sciolyff/validator/tournament.rb', line 78
def bids_per_school_relevant?(tournament, logger)
return true unless tournament[:'bids per school'] &&
!tournament.key?(:bids)
logger.error "field 'bids per school:' not relevant without field 'bids:'"
end
|
#bids_within_range?(tournament, logger) ⇒ Boolean
115
116
117
|
# File 'lib/sciolyff/validator/tournament.rb', line 115
def bids_within_range?(tournament, logger)
within_range?(tournament, :bids, logger, 1, @schools_count)
end
|
#maximum_place_within_range?(tournament, logger) ⇒ Boolean
102
103
104
|
# File 'lib/sciolyff/validator/tournament.rb', line 102
def maximum_place_within_range?(tournament, logger)
within_range?(tournament, :'maximum place', logger, 1, @maximum_place)
end
|
#medals_within_range?(tournament, logger) ⇒ Boolean
106
107
108
109
|
# File 'lib/sciolyff/validator/tournament.rb', line 106
def medals_within_range?(tournament, logger)
max = [@maximum_place, tournament[:'maximum place']].compact.min
within_range?(tournament, :medals, logger, 1, max)
end
|
#name_for_not_states_or_nationals?(tournament, logger) ⇒ Boolean
42
43
44
45
46
47
48
|
# File 'lib/sciolyff/validator/tournament.rb', line 42
def name_for_not_states_or_nationals?(tournament, logger)
level = tournament[:level]
return true if %w[States Nationals].include?(level) || tournament[:name]
logger.error 'name for Tournament required '\
"('level: #{level}' is not States or Nationals)"
end
|
#short_name_is_relevant?(tournament, logger) ⇒ Boolean
85
86
87
88
89
90
|
# File 'lib/sciolyff/validator/tournament.rb', line 85
def short_name_is_relevant?(tournament, logger)
return true unless tournament[:'short name'] && !tournament[:name]
logger.error "'short name: #{tournament[:'short name']}' for Tournament "\
"requires a normal 'name:' as well"
end
|
#short_name_is_short?(tournament, logger) ⇒ Boolean
92
93
94
95
96
97
98
|
# File 'lib/sciolyff/validator/tournament.rb', line 92
def short_name_is_short?(tournament, logger)
return true if tournament[:'short name'].nil? ||
tournament[:'short name'].length < tournament[:name].length
logger.error "'short name: #{tournament[:'short name']}' for Tournament "\
"is longer than normal 'name: #{tournament[:name]}'"
end
|
#state_for_not_nationals?(tournament, logger) ⇒ Boolean
50
51
52
53
54
55
|
# File 'lib/sciolyff/validator/tournament.rb', line 50
def state_for_not_nationals?(tournament, logger)
return true if tournament[:level] == 'Nationals' || tournament[:state]
logger.error 'state for Tournament required '\
"('level: #{tournament[:level]}' is not Nationals)"
end
|
#trophies_within_range?(tournament, logger) ⇒ Boolean
111
112
113
|
# File 'lib/sciolyff/validator/tournament.rb', line 111
def trophies_within_range?(tournament, logger)
within_range?(tournament, :trophies, logger, 1, @maximum_place)
end
|