basketball 0.0.8 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +9 -19
  3. data/CHANGELOG.md +1 -39
  4. data/README.md +75 -93
  5. data/basketball.gemspec +3 -6
  6. data/exe/{basketball-season-scheduling → basketball-coordinator} +1 -1
  7. data/exe/{basketball-draft → basketball-room} +1 -1
  8. data/lib/basketball/app/coordinator_cli.rb +250 -0
  9. data/lib/basketball/app/coordinator_repository.rb +114 -0
  10. data/lib/basketball/app/document_repository.rb +67 -0
  11. data/lib/basketball/app/file_store.rb +38 -0
  12. data/lib/basketball/app/in_memory_store.rb +42 -0
  13. data/lib/basketball/app/league_repository.rb +20 -0
  14. data/lib/basketball/app/league_serializable.rb +54 -0
  15. data/lib/basketball/{draft/cli.rb → app/room_cli.rb} +74 -80
  16. data/lib/basketball/app/room_repository.rb +149 -0
  17. data/lib/basketball/app.rb +20 -0
  18. data/lib/basketball/draft/assessment.rb +31 -0
  19. data/lib/basketball/draft/event.rb +3 -2
  20. data/lib/basketball/draft/front_office.rb +35 -28
  21. data/lib/basketball/draft/{pick_event.rb → pick.rb} +13 -6
  22. data/lib/basketball/draft/room.rb +119 -119
  23. data/lib/basketball/draft/{player_search.rb → scout.rb} +4 -9
  24. data/lib/basketball/draft/skip.rb +12 -0
  25. data/lib/basketball/draft.rb +13 -6
  26. data/lib/basketball/entity.rb +19 -10
  27. data/lib/basketball/org/league.rb +68 -0
  28. data/lib/basketball/org/player.rb +26 -0
  29. data/lib/basketball/{draft → org}/position.rb +3 -2
  30. data/lib/basketball/org/team.rb +38 -0
  31. data/lib/basketball/org.rb +12 -0
  32. data/lib/basketball/season/arena.rb +113 -0
  33. data/lib/basketball/season/calendar.rb +41 -72
  34. data/lib/basketball/season/coordinator.rb +186 -128
  35. data/lib/basketball/season/{preseason_game.rb → exhibition.rb} +2 -1
  36. data/lib/basketball/season/game.rb +15 -10
  37. data/lib/basketball/season/matchup.rb +27 -0
  38. data/lib/basketball/season/opponent.rb +15 -0
  39. data/lib/basketball/season/{season_game.rb → regular.rb} +2 -1
  40. data/lib/basketball/season/result.rb +37 -0
  41. data/lib/basketball/season.rb +12 -13
  42. data/lib/basketball/value_object.rb +8 -27
  43. data/lib/basketball/value_object_dsl.rb +30 -0
  44. data/lib/basketball/version.rb +1 -1
  45. data/lib/basketball.rb +9 -4
  46. metadata +37 -44
  47. data/lib/basketball/draft/league.rb +0 -70
  48. data/lib/basketball/draft/player.rb +0 -43
  49. data/lib/basketball/draft/room_serializer.rb +0 -186
  50. data/lib/basketball/draft/roster.rb +0 -37
  51. data/lib/basketball/draft/sim_event.rb +0 -23
  52. data/lib/basketball/draft/skip_event.rb +0 -13
  53. data/lib/basketball/season/calendar_serializer.rb +0 -94
  54. data/lib/basketball/season/conference.rb +0 -57
  55. data/lib/basketball/season/division.rb +0 -43
  56. data/lib/basketball/season/league.rb +0 -114
  57. data/lib/basketball/season/league_serializer.rb +0 -99
  58. data/lib/basketball/season/scheduling_cli.rb +0 -198
  59. data/lib/basketball/season/team.rb +0 -21
@@ -1,198 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'calendar_serializer'
4
- require_relative 'conference'
5
- require_relative 'coordinator'
6
- require_relative 'division'
7
- require_relative 'league'
8
- require_relative 'league_serializer'
9
- require_relative 'team'
10
-
11
- module Basketball
12
- module Season
13
- # Examples:
14
- # exe/basketball-season-scheduling -o tmp/league.json
15
- # exe/basketball-season-scheduling -i tmp/league.json -o tmp/calendar.json
16
- # exe/basketball-season-scheduling -i tmp/league.json -o tmp/calendar.json -y 2005
17
- # exe/basketball-season-scheduling -c tmp/calendar.json
18
- # exe/basketball-season-scheduling -c tmp/calendar.json -t C0-D0-T0
19
- # exe/basketball-season-scheduling -c tmp/calendar.json -d 2005-02-03
20
- # exe/basketball-season-scheduling -c tmp/calendar.json -d 2005-02-03 -t C0-D0-T0
21
- class SchedulingCLI
22
- attr_reader :opts,
23
- :league_serializer,
24
- :calendar_serializer,
25
- :io,
26
- :coordinator
27
-
28
- def initialize(args:, io: $stdout)
29
- @io = io
30
- @opts = slop_parse(args)
31
- @league_serializer = LeagueSerializer.new
32
- @calendar_serializer = CalendarSerializer.new
33
- @coordinator = Coordinator.new
34
-
35
- freeze
36
- end
37
-
38
- def invoke!
39
- if output?
40
- out_dir = File.dirname(output)
41
- FileUtils.mkdir_p(out_dir)
42
- end
43
-
44
- if output? && no_input?
45
- execute_with_no_input
46
- elsif output?
47
- execute_with_input
48
- end
49
-
50
- output_cal_query if cal
51
-
52
- self
53
- end
54
-
55
- private
56
-
57
- def output_cal_query
58
- contents = File.read(cal)
59
- calendar = calendar_serializer.deserialize(contents)
60
- team_instance = team ? calendar.team(team) : nil
61
- games = calendar.games_for(date:, team: team_instance).sort_by(&:date)
62
- pre_counter = 1
63
- counter = 1
64
-
65
- io.puts("Games for [team: #{team}, date: #{date}]")
66
- games.each do |game|
67
- if game.is_a?(PreseasonGame)
68
- io.puts("##{pre_counter} - #{game}")
69
- pre_counter += 1
70
- else
71
- io.puts("##{counter} - #{game}")
72
- counter += 1
73
- end
74
- end
75
- end
76
-
77
- def execute_with_input
78
- io.puts("Loading league from: #{input}")
79
-
80
- contents = File.read(input)
81
- league = league_serializer.deserialize(contents)
82
-
83
- io.puts("Generating calendar for the year #{year}...")
84
-
85
- calendar = coordinator.schedule(league:, year:)
86
- contents = calendar_serializer.serialize(calendar)
87
-
88
- File.write(output, contents)
89
-
90
- io.puts("Calendar written to: #{output}")
91
- end
92
-
93
- def execute_with_no_input
94
- league = generate_league
95
- contents = league_serializer.serialize(league)
96
-
97
- File.write(output, contents)
98
-
99
- io.puts("League written to: #{output}")
100
- end
101
-
102
- def cal
103
- opts[:cal].to_s.empty? ? nil : opts[:cal]
104
- end
105
-
106
- def team
107
- opts[:team].to_s.empty? ? nil : opts[:team]
108
- end
109
-
110
- def date
111
- opts[:date].to_s.empty? ? nil : Date.parse(opts[:date])
112
- end
113
-
114
- def year
115
- opts[:year].to_s.empty? ? Date.today.year : opts[:year]
116
- end
117
-
118
- def no_input?
119
- input.to_s.empty?
120
- end
121
-
122
- def input
123
- opts[:input]
124
- end
125
-
126
- def output?
127
- !output.to_s.empty?
128
- end
129
-
130
- def output
131
- opts[:output]
132
- end
133
-
134
- def generate_conferences
135
- 2.times.map do |i|
136
- id = "C#{i}"
137
-
138
- Conference.new(
139
- id:,
140
- name: Faker::Esport.league,
141
- divisions: generate_divisions("#{id}-")
142
- )
143
- end
144
- end
145
-
146
- def generate_divisions(id_prefix)
147
- 3.times.map do |j|
148
- id = "#{id_prefix}D#{j}"
149
-
150
- Division.new(
151
- id:,
152
- name: Faker::Address.community,
153
- teams: generate_teams("#{id}-")
154
- )
155
- end
156
- end
157
-
158
- def generate_teams(id_prefix)
159
- 5.times.map do |k|
160
- Team.new(
161
- id: "#{id_prefix}T#{k}",
162
- name: Faker::Team.name
163
- )
164
- end
165
- end
166
-
167
- def generate_league
168
- League.new(conferences: generate_conferences)
169
- end
170
-
171
- def slop_parse(args)
172
- Slop.parse(args) do |o|
173
- o.banner = 'Usage: basketball-schedule [options] ...'
174
-
175
- output_description = <<~DESC
176
- If input path is omitted then a new league will be written to this path.
177
- If an input path is specified then a Calendar will be written to the output path.
178
- DESC
179
-
180
- # League and Calendar Generation Interface
181
- o.string '-i', '--input', 'Path to load the League from. If omitted then a new league will be generated.'
182
- o.string '-o', '--output', output_description
183
- o.integer '-y', '--year', 'Year to use to generate a calendar for (defaults to current year).'
184
-
185
- # Calendar Query Interface
186
- o.string '-c', '--cal', 'Path to load a Calendar from. If omitted then no matchups will be outputted.'
187
- o.string '-d', '--date', 'Filter matchups to just the date specified (requires --cal option).'
188
- o.string '-t', '--team', 'Filter matchups to just the team ID specified (requires --cal option).'
189
-
190
- o.on '-h', '--help', 'Print out help, like this is doing right now.' do
191
- io.puts(o)
192
- exit
193
- end
194
- end.to_h
195
- end
196
- end
197
- end
198
- end
@@ -1,21 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Basketball
4
- module Season
5
- class Team < Entity
6
- attr_reader :name
7
-
8
- def initialize(id:, name: '')
9
- super(id)
10
-
11
- @name = name.to_s
12
-
13
- freeze
14
- end
15
-
16
- def to_s
17
- "[#{super}] #{name}"
18
- end
19
- end
20
- end
21
- end