Class: SportsManager::Tournament
- 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
-
#groups ⇒ Object
readonly
Returns the value of attribute groups.
-
#settings ⇒ Object
readonly
Returns the value of attribute settings.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #categories ⇒ Object
- #find_matches(category:, round:) ⇒ Object
- #find_participant_matches(participant) ⇒ Object
- #first_round_matches ⇒ Object
-
#initialize(settings: nil, groups: nil) ⇒ Tournament
constructor
A new instance of Tournament.
- #matches ⇒ Object
- #multi_tournament_participants ⇒ Object
- #participants ⇒ Object
- #total_matches ⇒ Object
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
#groups ⇒ Object (readonly)
Returns the value of attribute groups.
8 9 10 |
# File 'lib/sports_manager/tournament.rb', line 8 def groups @groups end |
#settings ⇒ Object (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 |
#categories ⇒ Object
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_matches ⇒ Object
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 |
#matches ⇒ Object
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_participants ⇒ Object
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 |
#participants ⇒ Object
50 51 52 |
# File 'lib/sports_manager/tournament.rb', line 50 def participants @participants ||= all_participants.uniq(&:id) end |
#total_matches ⇒ Object
46 47 48 |
# File 'lib/sports_manager/tournament.rb', line 46 def total_matches matches.values.map(&:size).sum end |