Class: SportsManager::Tournament

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/sports_manager/tournament.rb,
lib/sports_manager/tournament/setting.rb

Overview

Public: A tournament with different categories matches

Defined Under Namespace

Classes: Setting

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(settings: nil, groups: nil) ⇒ Tournament

Returns a new instance of Tournament.



13
14
15
16
# File 'lib/sports_manager/tournament.rb', line 13

def initialize(settings: nil, groups: nil)
  @settings = settings
  @groups = groups
end

Instance Attribute Details

#groupsObject (readonly)

Returns the value of attribute groups.



8
9
10
# File 'lib/sports_manager/tournament.rb', line 8

def groups
  @groups
end

#settingsObject (readonly)

Returns the value of attribute settings.



8
9
10
# File 'lib/sports_manager/tournament.rb', line 8

def settings
  @settings
end

Instance Method Details

#==(other) ⇒ Object



18
19
20
# File 'lib/sports_manager/tournament.rb', line 18

def ==(other)
  settings == other.settings && groups == other.groups
end

#categoriesObject



22
23
24
# File 'lib/sports_manager/tournament.rb', line 22

def categories
  @categories ||= groups.map(&:category)
end

#find_matches(category:, round:) ⇒ Object



38
39
40
41
42
43
44
# File 'lib/sports_manager/tournament.rb', line 38

def find_matches(category:, round:)
  category_matches = groups
    .find { |group| group.category == category }
    &.find_matches(round)

  category_matches || []
end

#find_participant_matches(participant) ⇒ Object



59
60
61
# File 'lib/sports_manager/tournament.rb', line 59

def find_participant_matches(participant)
  groups.flat_map { |group| group.find_participant_matches(participant) }
end

#first_round_matchesObject



32
33
34
35
36
# File 'lib/sports_manager/tournament.rb', line 32

def first_round_matches
  categories.each_with_object({}) do |category, first_rounds|
    first_rounds[category] = find_matches(category: category, round: 0)
  end
end

#matchesObject



26
27
28
29
30
# File 'lib/sports_manager/tournament.rb', line 26

def matches
  @matches ||= groups.each_with_object({}) do |group, category_matches|
    category_matches[group.category] = group.matches
  end
end

#multi_tournament_participantsObject



54
55
56
57
# File 'lib/sports_manager/tournament.rb', line 54

def multi_tournament_participants
  @multi_tournament_participants ||= participants
    .select { |participant| all_participants.count(participant) > 1 }
end

#participantsObject



50
51
52
# File 'lib/sports_manager/tournament.rb', line 50

def participants
  @participants ||= all_participants.uniq(&:id)
end

#total_matchesObject



46
47
48
# File 'lib/sports_manager/tournament.rb', line 46

def total_matches
  matches.values.map(&:size).sum
end