class SciolyFF::Interpreter::Tournament

Models a Science Olympiad tournament

Attributes

events[R]
penalties[R]
placings[R]
subdivisions[R]
teams[R]

Public Class Methods

new(rep) click to toggle source
# File lib/sciolyff/interpreter/tournament.rb, line 9
def initialize(rep)
  @rep = rep[:Tournament]
end

Public Instance Methods

bids() click to toggle source
# File lib/sciolyff/interpreter/tournament.rb, line 56
def bids
  @rep[:bids] || 0
end
bids_per_school() click to toggle source
# File lib/sciolyff/interpreter/tournament.rb, line 60
def bids_per_school
  @rep[:'bids per school'] || 1
end
custom_maximum_place?() click to toggle source
# File lib/sciolyff/interpreter/tournament.rb, line 80
def custom_maximum_place?
  maximum_place != nonexhibition_teams_count
end
date() click to toggle source
# File lib/sciolyff/interpreter/tournament.rb, line 40
def date
  @date ||= if @rep[:date].instance_of?(Date)
              @rep[:date]
            else
              Date.parse(@rep[:date])
            end
end
exempt_placings() click to toggle source
# File lib/sciolyff/interpreter/tournament.rb, line 76
def exempt_placings
  @rep[:'exempt placings'] || 0
end
exempt_placings?() click to toggle source
# File lib/sciolyff/interpreter/tournament.rb, line 72
def exempt_placings?
  exempt_placings.positive?
end
maximum_place() click to toggle source
# File lib/sciolyff/interpreter/tournament.rb, line 84
def maximum_place
  return @rep[:'maximum place'] if @rep[:'maximum place']

  nonexhibition_teams_count
end
medals() click to toggle source
# File lib/sciolyff/interpreter/tournament.rb, line 48
def medals
  @rep[:medals] || [calc_medals, maximum_place].min
end
n_offset() click to toggle source
# File lib/sciolyff/interpreter/tournament.rb, line 98
def n_offset
  @rep[:'n offset'] || 0
end
nonexhibition_teams_count() click to toggle source
# File lib/sciolyff/interpreter/tournament.rb, line 116
def nonexhibition_teams_count
  @nonexhibition_teams_count ||= @teams.count { |t| !t.exhibition? }
end
per_event_n() click to toggle source
# File lib/sciolyff/interpreter/tournament.rb, line 90
def per_event_n
  @rep[:'per-event n']
end
per_event_n?() click to toggle source
# File lib/sciolyff/interpreter/tournament.rb, line 94
def per_event_n?
  @rep.key? :'per-event n'
end
short_name() click to toggle source
# File lib/sciolyff/interpreter/tournament.rb, line 36
def short_name
  @rep[:'short name']
end
subdivisions?() click to toggle source
# File lib/sciolyff/interpreter/tournament.rb, line 112
def subdivisions?
  !@subdivisions.empty?
end
ties?() click to toggle source
# File lib/sciolyff/interpreter/tournament.rb, line 102
def ties?
  @ties ||= placings.map(&:tie?).any?
end
ties_outside_of_maximum_places?() click to toggle source
# File lib/sciolyff/interpreter/tournament.rb, line 106
def ties_outside_of_maximum_places?
  @ties_outside_of_maximum_places ||= placings.map do |p|
    p.tie? && !p.points_limited_by_maximum_place?
  end.any?
end
trophies() click to toggle source
# File lib/sciolyff/interpreter/tournament.rb, line 52
def trophies
  @rep[:trophies] || [calc_trophies, nonexhibition_teams_count].min
end
worst_placings_dropped() click to toggle source
# File lib/sciolyff/interpreter/tournament.rb, line 68
def worst_placings_dropped
  @rep[:'worst placings dropped'] || 0
end
worst_placings_dropped?() click to toggle source
# File lib/sciolyff/interpreter/tournament.rb, line 64
def worst_placings_dropped?
  worst_placings_dropped.positive?
end

Private Instance Methods

calc_medals() click to toggle source
# File lib/sciolyff/interpreter/tournament.rb, line 124
def calc_medals
  [(nonexhibition_teams_count / 10r).ceil, 3].max
end
calc_trophies() click to toggle source
# File lib/sciolyff/interpreter/tournament.rb, line 128
def calc_trophies
  [(nonexhibition_teams_count / 6r).ceil, 3].max
end