Class: SportsManager::TournamentBuilder
- Defined in:
- lib/sports_manager/tournament_builder.rb
Overview
Public: A step-by-step tournament constructor (Builder Pattern)
Constant Summary collapse
- DEFAULT_CONFIGURATIONS =
{ courts: 1, match_time: 60, break_time: 10, single_day_matches: false, tournament_type: Matches::Algorithms::SingleEliminationAlgorithm }.freeze
Instance Attribute Summary collapse
-
#categories ⇒ Object
readonly
Returns the value of attribute categories.
-
#configurations ⇒ Object
readonly
Returns the value of attribute configurations.
-
#matches ⇒ Object
readonly
Returns the value of attribute matches.
-
#subscriptions ⇒ Object
readonly
Returns the value of attribute subscriptions.
-
#tournament ⇒ Object
readonly
Returns the value of attribute tournament.
-
#tournament_days ⇒ Object
readonly
Returns the value of attribute tournament_days.
Instance Method Summary collapse
- #add_configuration(key:, value:) ⇒ Object
- #add_configurations(params) ⇒ Object
- #add_date(date:, start_hour:, end_hour:) ⇒ Object
- #add_match(category:, category_matches:) ⇒ Object
- #add_matches(matches) ⇒ Object
- #add_schedule(tournament_days) ⇒ Object
- #add_subscription(category:, participants:) ⇒ Object
- #add_subscriptions(subscriptions) ⇒ Object
- #build ⇒ Object
-
#initialize ⇒ TournamentBuilder
constructor
A new instance of TournamentBuilder.
Constructor Details
#initialize ⇒ TournamentBuilder
Returns a new instance of TournamentBuilder.
18 19 20 21 22 23 24 |
# File 'lib/sports_manager/tournament_builder.rb', line 18 def initialize @matches = {} @subscriptions = {} @categories = [] @tournament_days = [] @configurations = DEFAULT_CONFIGURATIONS end |
Instance Attribute Details
#categories ⇒ Object (readonly)
Returns the value of attribute categories.
6 7 8 |
# File 'lib/sports_manager/tournament_builder.rb', line 6 def categories @categories end |
#configurations ⇒ Object (readonly)
Returns the value of attribute configurations.
6 7 8 |
# File 'lib/sports_manager/tournament_builder.rb', line 6 def configurations @configurations end |
#matches ⇒ Object (readonly)
Returns the value of attribute matches.
6 7 8 |
# File 'lib/sports_manager/tournament_builder.rb', line 6 def matches @matches end |
#subscriptions ⇒ Object (readonly)
Returns the value of attribute subscriptions.
6 7 8 |
# File 'lib/sports_manager/tournament_builder.rb', line 6 def subscriptions @subscriptions end |
#tournament ⇒ Object (readonly)
Returns the value of attribute tournament.
6 7 8 |
# File 'lib/sports_manager/tournament_builder.rb', line 6 def tournament @tournament end |
#tournament_days ⇒ Object (readonly)
Returns the value of attribute tournament_days.
6 7 8 |
# File 'lib/sports_manager/tournament_builder.rb', line 6 def tournament_days @tournament_days end |
Instance Method Details
#add_configuration(key:, value:) ⇒ Object
60 61 62 63 64 65 66 |
# File 'lib/sports_manager/tournament_builder.rb', line 60 def add_configuration(key:, value:) return self if [key, value].any?(nil) @configurations = @configurations.merge(key.to_sym => value) self end |
#add_configurations(params) ⇒ Object
68 69 70 71 72 |
# File 'lib/sports_manager/tournament_builder.rb', line 68 def add_configurations(params) params.each { |key, value| add_configuration(key: key, value: value) } self end |
#add_date(date:, start_hour:, end_hour:) ⇒ Object
85 86 87 88 89 90 91 92 93 |
# File 'lib/sports_manager/tournament_builder.rb', line 85 def add_date(date:, start_hour:, end_hour:) @tournament_days << TournamentDay.for( date: date, start_hour: start_hour, end_hour: end_hour ) self end |
#add_match(category:, category_matches:) ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/sports_manager/tournament_builder.rb', line 38 def add_match(category:, category_matches:) return self if [category, category_matches].any?(nil) @matches.merge!(category => category_matches) self end |
#add_matches(matches) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/sports_manager/tournament_builder.rb', line 30 def add_matches(matches) matches.each do |category, category_matches| add_match(category: category, category_matches: category_matches) end self end |
#add_schedule(tournament_days) ⇒ Object
74 75 76 77 78 79 80 81 82 83 |
# File 'lib/sports_manager/tournament_builder.rb', line 74 def add_schedule(tournament_days) tournament_days.each do |date, period| add_date( date: date, start_hour: period[:start], end_hour: period[:end] ) end self end |
#add_subscription(category:, participants:) ⇒ Object
46 47 48 49 50 |
# File 'lib/sports_manager/tournament_builder.rb', line 46 def add_subscription(category:, participants:) @subscriptions.merge!(category => participants) self end |
#add_subscriptions(subscriptions) ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/sports_manager/tournament_builder.rb', line 52 def add_subscriptions(subscriptions) subscriptions.each do |category, participants| add_subscription(category: category, participants: participants) end self end |
#build ⇒ Object
26 27 28 |
# File 'lib/sports_manager/tournament_builder.rb', line 26 def build Tournament.new(settings: settings, groups: groups) end |