Class: SportsManager::Group

Inherits:
Object show all
Defined in:
lib/sports_manager/group.rb

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

Class Method Summary collapse

Instance Method Summary collapse

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_matchesObject (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

#categoryObject (readonly)

Returns the value of attribute category.



7
8
9
# File 'lib/sports_manager/group.rb', line 7

def category
  @category
end

#teamsObject (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_matchesObject



28
29
30
# File 'lib/sports_manager/group.rb', line 28

def first_round_matches
  find_matches(0)
end

#matchesObject



24
25
26
# File 'lib/sports_manager/group.rb', line 24

def matches
  @matches ||= all_matches.select(&:playable?)
end

#participantsObject



20
21
22
# File 'lib/sports_manager/group.rb', line 20

def participants
  @participants ||= teams.map(&:participants).flatten
end