class Olympic::Bracket::SingleElimination
A single elimination tournament. A single elimination tournament is a tournament of a set of teams in which the first loss results in elimination from the tournament. Single elimination tournaments have the problem in which when the number of teams is not equal to a power of two, at least one bye is required.
Public Instance Methods
call()
click to toggle source
Creates a single elimination tournament, by setting up the needed matches (and their respective sources).
# File lib/olympic/bracket/single_elimination.rb, line 19 def call matches = pair(initial_sources) @tournament.root = matches.sort_by(&:depth).last end
Private Instance Methods
initial_sources()
click to toggle source
The initial sources. The “sources” in this case are the teams, which are mapped to an actual {Olympic::Source}.
@return [Array<Olympic::Source>] The initial sources.
# File lib/olympic/bracket/single_elimination.rb, line 48 def initial_sources @teams.map { |team| Settings.class_for(:source).create(source: team) } end
pair(incoming, depth = 1)
click to toggle source
# File lib/olympic/bracket/single_elimination.rb, line 26 def pair(incoming, depth = 1) round = incoming.each_slice(2).each_with_index. map { |pair, i| match = Settings.class_for(:match). create(incoming: pair, tournament: @tournament, depth: depth, offset: i) } if round.length > 1 outgoing = round. map { |match| Settings.class_for(:source).create(source: match) } round + pair(outgoing, depth + 1) else round end end