Class: SportsManager::Group
Overview
TODO: change the name Group. In terms of sports tournament it means something else. Public: A category with teams and matches between them
Instance Attribute Summary collapse
-
#all_matches ⇒ Object
readonly
Returns the value of attribute all_matches.
-
#category ⇒ Object
readonly
Returns the value of attribute category.
-
#teams ⇒ Object
readonly
Returns the value of attribute teams.
Class Method Summary collapse
Instance Method Summary collapse
- #find_matches(round_number) ⇒ Object
- #find_participant_matches(participant) ⇒ Object
- #first_round_matches ⇒ Object
-
#initialize(category: nil, matches: nil, teams: nil) ⇒ Group
constructor
A new instance of Group.
- #matches ⇒ Object
- #participants ⇒ Object
Constructor Details
#initialize(category: nil, matches: nil, teams: nil) ⇒ Group
Returns a new instance of Group.
14 15 16 17 18 |
# File 'lib/sports_manager/group.rb', line 14 def initialize(category: nil, matches: nil, teams: nil) @category = category @all_matches = matches @teams = teams end |
Instance Attribute Details
#all_matches ⇒ Object (readonly)
Returns the value of attribute all_matches.
7 8 9 |
# File 'lib/sports_manager/group.rb', line 7 def all_matches @all_matches end |
#category ⇒ Object (readonly)
Returns the value of attribute category.
7 8 9 |
# File 'lib/sports_manager/group.rb', line 7 def category @category end |
#teams ⇒ Object (readonly)
Returns the value of attribute teams.
7 8 9 |
# File 'lib/sports_manager/group.rb', line 7 def teams @teams end |
Class Method Details
.for(category:, subscriptions:, matches:, tournament_type:) ⇒ Object
9 10 11 12 |
# File 'lib/sports_manager/group.rb', line 9 def self.for(category:, subscriptions:, matches:, tournament_type:) GroupBuilder.new(category: category, subscriptions: subscriptions, matches: matches, tournament_type: tournament_type).build end |
Instance Method Details
#find_matches(round_number) ⇒ Object
32 33 34 |
# File 'lib/sports_manager/group.rb', line 32 def find_matches(round_number) matches.select { |match| match.round == round_number } end |
#find_participant_matches(participant) ⇒ Object
36 37 38 39 40 |
# File 'lib/sports_manager/group.rb', line 36 def find_participant_matches(participant) matches.select do |match| match.participants.include? participant end end |
#first_round_matches ⇒ Object
28 29 30 |
# File 'lib/sports_manager/group.rb', line 28 def first_round_matches find_matches(0) end |
#matches ⇒ Object
24 25 26 |
# File 'lib/sports_manager/group.rb', line 24 def matches @matches ||= all_matches.select(&:playable?) end |
#participants ⇒ Object
20 21 22 |
# File 'lib/sports_manager/group.rb', line 20 def participants @participants ||= teams.map(&:participants).flatten end |