Class: SportsManager::Match
Overview
Public: A category’s match with teams, which rounds is ocurring and which matches its depends on before happening.
Instance Attribute Summary collapse
-
#category ⇒ Object
readonly
Returns the value of attribute category.
-
#depends_on ⇒ Object
readonly
Returns the value of attribute depends_on.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#round ⇒ Object
readonly
Returns the value of attribute round.
-
#team1 ⇒ Object
readonly
Returns the value of attribute team1.
-
#team2 ⇒ Object
readonly
Returns the value of attribute team2.
-
#teams ⇒ Object
readonly
Returns the value of attribute teams.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #dependencies ⇒ Object
- #dependencies? ⇒ Boolean
-
#initialize(category:, id: nil, team1: nil, team2: nil, round: 0, depends_on: []) ⇒ Match
constructor
rubocop:disable Metrics/ParameterLists.
- #participants ⇒ Object
- #playable? ⇒ Boolean
- #playable_dependencies ⇒ Object
- #previous_matches ⇒ Object
- #previous_matches? ⇒ Boolean
- #teams_names ⇒ Object
- #title(title_format: 'M%<id>s') ⇒ Object
Constructor Details
#initialize(category:, id: nil, team1: nil, team2: nil, round: 0, depends_on: []) ⇒ Match
rubocop:disable Metrics/ParameterLists
20 21 22 23 24 25 26 27 28 |
# File 'lib/sports_manager/match.rb', line 20 def initialize(category:, id: nil, team1: nil, team2: nil, round: 0, depends_on: []) # rubocop:disable Metrics/ParameterLists @id = id @category = category @team1 = team1 @team2 = team2 @round = round @teams = [team1, team2].compact @depends_on = depends_on end |
Instance Attribute Details
#category ⇒ Object (readonly)
Returns the value of attribute category.
7 8 9 |
# File 'lib/sports_manager/match.rb', line 7 def category @category end |
#depends_on ⇒ Object (readonly)
Returns the value of attribute depends_on.
7 8 9 |
# File 'lib/sports_manager/match.rb', line 7 def depends_on @depends_on end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
7 8 9 |
# File 'lib/sports_manager/match.rb', line 7 def id @id end |
#round ⇒ Object (readonly)
Returns the value of attribute round.
7 8 9 |
# File 'lib/sports_manager/match.rb', line 7 def round @round end |
#team1 ⇒ Object (readonly)
Returns the value of attribute team1.
7 8 9 |
# File 'lib/sports_manager/match.rb', line 7 def team1 @team1 end |
#team2 ⇒ Object (readonly)
Returns the value of attribute team2.
7 8 9 |
# File 'lib/sports_manager/match.rb', line 7 def team2 @team2 end |
#teams ⇒ Object (readonly)
Returns the value of attribute teams.
7 8 9 |
# File 'lib/sports_manager/match.rb', line 7 def teams @teams end |
Class Method Details
.build_next_match(category:, depends_on:, id: nil, round: 0) ⇒ Object
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/sports_manager/match.rb', line 9 def self.build_next_match(category:, depends_on:, id: nil, round: 0) new( id: id, category: category, round: round, depends_on: depends_on, team1: NilTeam.new(category: category), team2: NilTeam.new(category: category) ) end |
Instance Method Details
#==(other) ⇒ Object
73 74 75 76 77 |
# File 'lib/sports_manager/match.rb', line 73 def ==(other) return false unless instance_of?(other.class) id == other.id && category == other.category && round == other.round end |
#dependencies ⇒ Object
42 43 44 45 |
# File 'lib/sports_manager/match.rb', line 42 def dependencies @dependencies ||= depends_on .flat_map { |match| [match, *match.depends_on] } end |
#dependencies? ⇒ Boolean
38 39 40 |
# File 'lib/sports_manager/match.rb', line 38 def dependencies? depends_on && !depends_on.empty? end |
#participants ⇒ Object
34 35 36 |
# File 'lib/sports_manager/match.rb', line 34 def participants @participants ||= teams.map(&:participants).flatten end |
#playable? ⇒ Boolean
30 31 32 |
# File 'lib/sports_manager/match.rb', line 30 def playable? true end |
#playable_dependencies ⇒ Object
47 48 49 |
# File 'lib/sports_manager/match.rb', line 47 def playable_dependencies depends_on.select(&:playable?) end |
#previous_matches ⇒ Object
55 56 57 |
# File 'lib/sports_manager/match.rb', line 55 def previous_matches playable_dependencies.flat_map { |match| [match, *match.previous_matches] } end |
#previous_matches? ⇒ Boolean
51 52 53 |
# File 'lib/sports_manager/match.rb', line 51 def previous_matches? previous_matches && !previous_matches.empty? end |
#teams_names ⇒ Object
69 70 71 |
# File 'lib/sports_manager/match.rb', line 69 def teams_names teams.map(&:name) end |
#title(title_format: 'M%<id>s') ⇒ Object
59 60 61 62 63 64 65 66 67 |
# File 'lib/sports_manager/match.rb', line 59 def title(title_format: 'M%<id>s') match_participants = if previous_matches? depends_on_names(title_format) else teams_names end match_participants.join(' vs. ') end |