Class: SciolyFF::Validator::Tournament

Inherits:
Checker
  • Object
show all
Includes:
Sections
Defined in:
lib/sciolyff/validator/tournament.rb

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,
  'short name': String,
  'worst placings dropped': Integer,
  'exempt placings': Integer,
  'maximum place': Integer,
  'per-event n': [true, false],
  'n offset': Integer
}.freeze

Instance Method Summary collapse

Methods included from Sections

#all_required_sections?, #no_extra_sections?, #sections_are_correct_type?

Methods inherited from Checker

#send

Constructor Details

#initialize(rep) ⇒ Tournament

Returns a new instance of Tournament.



30
31
32
# File 'lib/sciolyff/validator/tournament.rb', line 30

def initialize(rep)
  @maximum_place = rep[:Teams].count { |t| !t[:exhibition] }
end

Instance Method Details

#maximum_place_within_range?(tournament, logger) ⇒ Boolean

Returns:

  • (Boolean)


64
65
66
67
68
69
70
# File 'lib/sciolyff/validator/tournament.rb', line 64

def maximum_place_within_range?(tournament, logger)
  return true if tournament[:'maximum place'].nil? ||
                 tournament[:'maximum place'].between?(1, @maximum_place)

  logger.error "custom 'maximum place: #{tournament[:'maximum place']}' "\
    "is not within range [1, #{@maximum_place}]"
end

#name_for_not_states_or_nationals?(tournament, logger) ⇒ Boolean

Returns:

  • (Boolean)


34
35
36
37
38
39
40
# File 'lib/sciolyff/validator/tournament.rb', line 34

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

Returns:

  • (Boolean)


49
50
51
52
53
54
# File 'lib/sciolyff/validator/tournament.rb', line 49

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

Returns:

  • (Boolean)


56
57
58
59
60
61
62
# File 'lib/sciolyff/validator/tournament.rb', line 56

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

Returns:

  • (Boolean)


42
43
44
45
46
47
# File 'lib/sciolyff/validator/tournament.rb', line 42

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