Class: Playoffs::Basketball

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/playoffs/basketball.rb

Overview

Knows how to create a tournament specific to professional basketball.

Class Method Summary collapse

Class Method Details

.tournament_for(eastern_teams:, western_teams:) ⇒ Object

Raises:



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/playoffs/basketball.rb', line 16

def self.tournament_for(eastern_teams:, western_teams:)
  eastern_teams = eastern_teams.uniq
  western_teams = western_teams.uniq

  raise IncorrectTeamCount unless eastern_teams.size == 10
  raise IncorrectTeamCount unless western_teams.size == 10

  play_in_best_of = BestOf.new(1)

  eastern_play_in78 = Series.new(best_of: play_in_best_of)
    .register(T.must(eastern_teams[6]))
    .register(T.must(eastern_teams[7]))

  eastern_play_in910 = Series
    .new(best_of: play_in_best_of)
    .register(T.must(eastern_teams[8]))
    .register(T.must(eastern_teams[9]))

  eastern_play_in_consolation = Series
    .new(best_of: play_in_best_of)
    .loser_of(eastern_play_in78)
    .winner_of(eastern_play_in910)

  western_play_in78 = Series
    .new(best_of: play_in_best_of)
    .register(T.must(western_teams[6]))
    .register(T.must(western_teams[7]))

  western_play_in910 = Series
    .new(best_of: play_in_best_of)
    .register(T.must(western_teams[8]))
    .register(T.must(western_teams[9]))

  western_play_in_consolation = Series
    .new(best_of: play_in_best_of)
    .loser_of(western_play_in78)
    .loser_of(western_play_in910)

  championship =
    Series
      .new
      .winner_of(
        Series.new
          .winner_of(
            Series.new
              .winner_of(
                Series.new
                  .register(T.must(eastern_teams[0]))
                  .winner_of(eastern_play_in_consolation)
              )
              .winner_of(
                Series.new
                  .register(T.must(eastern_teams[3]))
                  .register(T.must(eastern_teams[4]))
              )
          )
          .winner_of(
            Series.new
              .winner_of(
                Series.new
                  .register(T.must(eastern_teams[2]))
                  .register(T.must(eastern_teams[5]))
              )
              .winner_of(
                Series.new
                  .register(T.must(eastern_teams[1]))
                  .winner_of(eastern_play_in78)
              )
          )
      )
      .winner_of(
        Series.new
          .winner_of(
            Series.new
              .winner_of(
                Series.new
                  .register(T.must(western_teams[0]))
                  .winner_of(western_play_in_consolation)
              )
              .winner_of(
                Series.new
                  .register(T.must(western_teams[3]))
                  .register(T.must(western_teams[4]))
              )
          )
          .winner_of(
            Series.new
              .winner_of(
                Series.new
                  .register(T.must(western_teams[2]))
                  .register(T.must(western_teams[5]))
              )
              .winner_of(
                Series.new
                  .register(T.must(western_teams[1]))
                  .winner_of(western_play_in78)
              )
          )
      )

  Tournament.new(championship)
end