class SciolyFF::Validator::Placings

Checks for one placing in the Placings section of a SciolyFF file

Constants

OPTIONAL
REQUIRED

Public Class Methods

new(rep) click to toggle source
# 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

Public Instance Methods

having_a_place_makes_sense?(placing, logger) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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

Private Instance Methods

invalid_unknown?(placing, event, team) click to toggle source
# File lib/sciolyff/validator/placings.rb, line 118
def invalid_unknown?(placing, event, team)
  placing[:unknown] &&
    @maximum_place.nil? &&
    !placing[:exempt] &&
    !event[:trial] &&
    !event[:trialed] &&
    !team[:exhibition]
end
placing_log(placing) click to toggle source
# File lib/sciolyff/validator/placings.rb, line 114
def placing_log(placing)
  "placing with 'team: #{placing[:team]}' and 'event: #{placing[:event]}'"
end