class SciolyFF::Validator::Tournament

Checks for Tournament section of a SciolyFF file

Constants

OPTIONAL
REQUIRED

Public Class Methods

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

Public Instance Methods

bids_for_regionals_or_states?(tournament, logger) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# File lib/sciolyff/validator/tournament.rb, line 111
def trophies_within_range?(tournament, logger)
  within_range?(tournament, :trophies, logger, 1, @maximum_place)
end