class TeamSeeder
Attributes
size[R]
Public Class Methods
new(teams, size, shuffle: false)
click to toggle source
# File lib/bracket_graph/team_seeder.rb, line 4 def initialize teams, size, shuffle: false @teams = shuffle && teams.shuffle || teams.dup @size = size end
Public Instance Methods
slots()
click to toggle source
# File lib/bracket_graph/team_seeder.rb, line 9 def slots return @slots if @slots @slots = [true] * size seed_byes seed_teams @slots end
Private Instance Methods
largest_bye_partition()
click to toggle source
# File lib/bracket_graph/team_seeder.rb, line 41 def largest_bye_partition start_index, end_index = nil, nil prev_index = 0 @slots.each_with_index do |value, index| next if index > 0 && index < @slots.count - 1 && value if start_index.nil? start_index = index elsif end_index.nil? end_index = index elsif index - prev_index > end_index - start_index start_index, end_index = prev_index, index end prev_index = index end Range.new start_index, end_index end
seed_byes()
click to toggle source
# File lib/bracket_graph/team_seeder.rb, line 19 def seed_byes byes_to_seed = size - @teams.length return if byes_to_seed == 0 @slots[0] = nil seed_byes_by_partition byes_to_seed - 1 if byes_to_seed > 1 end
seed_byes_by_partition(byes)
click to toggle source
# File lib/bracket_graph/team_seeder.rb, line 32 def seed_byes_by_partition byes partition = nil byes.times do partition = largest_bye_partition mid_index = partition.min + ((partition.max.to_f - partition.min) / 2).ceil @slots[mid_index] = nil end end
seed_teams()
click to toggle source
# File lib/bracket_graph/team_seeder.rb, line 26 def seed_teams @slots.each_with_index do |slot_value, index| @slots[index] = @teams.shift if slot_value == true end end