class SciolyFF::Validator::Events
Checks for one event in the Events
section of a SciolyFF
file
Constants
- OPTIONAL
- REQUIRED
Public Class Methods
new(rep)
click to toggle source
# File lib/sciolyff/validator/events.rb, line 22 def initialize(rep) @events = rep[:Events] @names = @events.map { |e| e[:name] } @placings = rep[:Placings].group_by { |p| p[:event] } @teams = rep[:Teams].count end
Public Instance Methods
in_canonical_list?(event, logger)
click to toggle source
# File lib/sciolyff/validator/events.rb, line 84 def in_canonical_list?(event, logger) rep = [event[:name]] return true if canonical?(rep, 'events.csv', logger) logger.warn "non-canonical event: #{event[:name]}" end
no_gaps_in_places?(event, logger)
click to toggle source
# File lib/sciolyff/validator/events.rb, line 63 def no_gaps_in_places?(event, logger) places = places_with_expanded_ties(event) return true if places.empty? gaps = (places.min..places.max).to_a - places return true if gaps.empty? logger.error "'event: #{event[:name]}' has gaps in "\ "place #{gaps.join ', '}" end
places_start_at_one?(event, logger)
click to toggle source
# File lib/sciolyff/validator/events.rb, line 74 def places_start_at_one?(event, logger) lowest_place = @placings[event[:name]].map { |p| p[:place] }.compact.min return true if lowest_place == 1 || lowest_place.nil? logger.error "places for 'event: #{event[:name]}' start at "\ "#{lowest_place} instead of 1" end
placings_for_all_teams?(event, logger)
click to toggle source
# File lib/sciolyff/validator/events.rb, line 35 def placings_for_all_teams?(event, logger) count = @placings[event[:name]]&.count || 0 return true if count == @teams logger.error "'event: #{event[:name]}' has incorrect number of "\ "placings (#{count} instead of #{@teams})" end
ties_marked?(event, logger)
click to toggle source
# File lib/sciolyff/validator/events.rb, line 43 def ties_marked?(event, logger) unmarked_ties = placings_by_place(event).select do |_place, placings| placings.count { |p| !p[:tie] } > 1 end return true if unmarked_ties.empty? logger.error "'event: #{event[:name]}' has unmarked ties at "\ "place #{unmarked_ties.keys.join ', '}" end
ties_paired?(event, logger)
click to toggle source
# File lib/sciolyff/validator/events.rb, line 53 def ties_paired?(event, logger) unpaired_ties = placings_by_place(event).select do |_place, placings| placings.count { |p| p[:tie] } == 1 end return true if unpaired_ties.empty? logger.error "'event: #{event[:name]}' has unpaired ties at "\ "place #{unpaired_ties.keys.join ', '}" end
unique_name?(event, logger)
click to toggle source
# File lib/sciolyff/validator/events.rb, line 29 def unique_name?(event, logger) return true if @names.count(event[:name]) == 1 logger.error "duplicate event name: #{event[:name]}" end
Private Instance Methods
places_with_expanded_ties(event)
click to toggle source
# File lib/sciolyff/validator/events.rb, line 99 def places_with_expanded_ties(event) # e.g. [6, 6, 8] -> [6, 7, 8] placings_by_place(event).map do |place, placings| (place..(place + (placings.size - 1))).to_a end.flatten end
placings_by_place(event)
click to toggle source
# File lib/sciolyff/validator/events.rb, line 93 def placings_by_place(event) @placings[event[:name]] .select { |p| p[:place] } .group_by { |p| p[:place] } end