Module: Olympic::Bracket::SingleElimination::Information

Extended by:
Memoist
Included in:
Olympic::Bracket::SingleElimination
Defined in:
lib/olympic/bracket/single_elimination/information.rb

Overview

General information about the tournament.

See Also:

Instance Method Summary collapse

Instance Method Details

#byesNumeric

The number of byes that are required in the bracket. This should be greater than or equal to zero.

Returns:

  • (Numeric)


32
33
34
# File 'lib/olympic/bracket/single_elimination/information.rb', line 32

def byes
  rounded_teams - @teams.size
end

#first_round_matchesNumeric

The number of matches in the first round. This will always be a finite number, so this method will never return an array of numbers.

Returns:

  • (Numeric)


38
39
40
# File 'lib/olympic/bracket/single_elimination/information.rb', line 38

def first_round_matches
  @teams.size - 2 ** Math.log2(@teams.size).floor
end

#matchesNumeric+

Returns the number of expected matches in the bracket. If the number of matches is variable, it will return an array of numbers, which contains potential values for the number of matches in the bracket.

Returns:

  • (Numeric, Array<Numeric>)


14
15
16
# File 'lib/olympic/bracket/single_elimination/information.rb', line 14

def matches
  @teams.size - 1
end

#rounded_teamsNumeric

In an elimination tournament, the number of teams has to be rounded to the nearest power of two to calculate the number of byes. If this is not necessary, it will return the number of teams.

Returns:

  • (Numeric)


26
27
28
# File 'lib/olympic/bracket/single_elimination/information.rb', line 26

def rounded_teams
  2 ** rounds
end

#roundsNumeric+

Returns the number of expected rounds in the bracket. If the number of rounds is variable, it will return an array of numbers, which contains potential values for the number of rounds in the bracket.

Returns:

  • (Numeric, Array<Numeric>)


20
21
22
# File 'lib/olympic/bracket/single_elimination/information.rb', line 20

def rounds
  Math.log2(@teams.size).ceil
end