Class: SciolyFF::Validator::Placings
Overview
Checks for one placing in the Placings section of a SciolyFF file
Constant Summary
collapse
- REQUIRED =
{
event: String,
team: Integer
}.freeze
- OPTIONAL =
{
place: Integer,
participated: [true, false],
disqualified: [true, false],
exempt: [true, false],
tie: [true, false],
unknown: [true, false],
raw: Hash
}.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
#initialize(rep) ⇒ Placings
Returns a new instance of Placings.
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/sciolyff/validator/placings.rb', line 26
def initialize(rep)
@events_by_name = rep[:Events].group_by { |e| e[:name] }
.transform_values(&:first)
@teams_by_number = rep[:Teams].group_by { |t| t[:number] }
.transform_values(&:first)
@event_names = @events_by_name.keys
@team_numbers = @teams_by_number.keys
@placings = rep[:Placings]
@maximum_place = rep[:Tournament][:'maximum place']
end
|
Instance Method Details
#having_a_place_makes_sense?(placing, logger) ⇒ Boolean
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/sciolyff/validator/placings.rb', line 59
def having_a_place_makes_sense?(placing, logger)
return true unless placing[:place] &&
(placing[:participated] == false ||
placing[:disqualified] ||
placing[:unknown] ||
placing[:raw])
logger.error 'having a place does not make sense for '\
"#{placing_log(placing)}"
end
|
#having_a_raw_makes_sense?(placing, logger) ⇒ Boolean
70
71
72
73
74
75
76
77
78
79
|
# File 'lib/sciolyff/validator/placings.rb', line 70
def having_a_raw_makes_sense?(placing, logger)
return true unless placing[:raw] &&
(placing[:participated] == false ||
placing[:disqualified] ||
placing[:unknown] ||
placing[:place])
logger.error 'having raw section does not make sense for '\
"#{placing_log(placing)}"
end
|
#having_a_tie_makes_sense?(placing, logger) ⇒ Boolean
81
82
83
84
85
86
|
# File 'lib/sciolyff/validator/placings.rb', line 81
def having_a_tie_makes_sense?(placing, logger)
return true unless placing.key?(:tie) && placing[:raw]
logger.error 'having a tie value does make sense for '\
"#{placing_log(placing)}"
end
|
#matching_event?(placing, logger) ⇒ Boolean
37
38
39
40
41
42
|
# File 'lib/sciolyff/validator/placings.rb', line 37
def matching_event?(placing, logger)
return true if @event_names.include? placing[:event]
logger.error "'event: #{placing[:event]}' in Placings "\
'does not match any event name in Events'
end
|
#matching_team?(placing, logger) ⇒ Boolean
44
45
46
47
48
49
|
# File 'lib/sciolyff/validator/placings.rb', line 44
def matching_team?(placing, logger)
return true if @team_numbers.include? placing[:team]
logger.error "'team: #{placing[:team]}' in Placings "\
'does not match any team number in Teams'
end
|
#possible_participated_disqualified_combination?(placing, logger) ⇒ Boolean
88
89
90
91
92
93
94
|
# File 'lib/sciolyff/validator/placings.rb', line 88
def possible_participated_disqualified_combination?(placing, logger)
return true unless placing[:participated] == false &&
placing[:disqualified]
logger.error 'impossible participation-disqualified combination for '\
"#{placing_log(placing)}"
end
|
#possible_unknown_disqualified_combination?(placing, logger) ⇒ Boolean
96
97
98
99
100
101
|
# File 'lib/sciolyff/validator/placings.rb', line 96
def possible_unknown_disqualified_combination?(placing, logger)
return true unless placing[:unknown] && placing[:disqualified]
logger.error 'impossible unknown-disqualified combination for '\
"#{placing_log(placing)}"
end
|
#unique_event_and_team?(placing, logger) ⇒ Boolean
51
52
53
54
55
56
57
|
# File 'lib/sciolyff/validator/placings.rb', line 51
def unique_event_and_team?(placing, logger)
return true if @placings.count do |other|
placing[:event] == other[:event] && placing[:team] == other[:team]
end == 1
logger.error "duplicate #{placing_log(placing)}"
end
|
#unknown_allowed?(placing, logger) ⇒ Boolean
103
104
105
106
107
108
109
110
|
# File 'lib/sciolyff/validator/placings.rb', line 103
def unknown_allowed?(placing, logger)
event = @events_by_name[placing[:event]]
team = @teams_by_number[placing[:team]]
return true unless invalid_unknown?(placing, event, team)
logger.error "unknown place not allowed for #{placing_log(placing)} "\
'(either placing must be exempt or event must be trial/trialed)'
end
|