Class: Sportradar::Api::Football::Nfl
- Inherits:
-
Data
- Object
- Data
- Sportradar::Api::Football::Nfl
show all
- Defined in:
- lib/sportradar/api/football/nfl.rb,
lib/sportradar/api/football/nfl/api.rb,
lib/sportradar/api/football/nfl/game.rb,
lib/sportradar/api/football/nfl/play.rb,
lib/sportradar/api/football/nfl/team.rb,
lib/sportradar/api/football/nfl/week.rb,
lib/sportradar/api/football/nfl/drive.rb,
lib/sportradar/api/football/nfl/event.rb,
lib/sportradar/api/football/nfl/player.rb,
lib/sportradar/api/football/nfl/quarter.rb,
lib/sportradar/api/football/nfl/division.rb,
lib/sportradar/api/football/nfl/conference.rb,
lib/sportradar/api/football/nfl/depth_chart.rb,
lib/sportradar/api/football/nfl/team_depth_chart.rb,
lib/sportradar/api/football/nfl/league_depth_chart.rb
Defined Under Namespace
Classes: Api, Conference, DepthChart, Division, Drive, Event, Game, LeagueDepthChart, Play, Player, Quarter, Team, TeamDepthChart, Week
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Data
#attributes, #create_data, #parse_into_array, #parse_into_array_with_options, #parse_out_hashes, #structure_links, #update_data
Constructor Details
#initialize(data = {}, **opts) ⇒ Nfl
Returns a new instance of Nfl.
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/sportradar/api/football/nfl.rb', line 10
def initialize(data = {}, **opts)
@api = opts[:api]
@id = data['id']
@season = opts[:year]
@type = opts[:type]
@conferences_hash = {}
@weeks_hash = {}
@depth_charts_hash = {}
@games_hash = {}
@teams_hash = {}
end
|
Instance Attribute Details
#alias ⇒ Object
Returns the value of attribute alias.
5
6
7
|
# File 'lib/sportradar/api/football/nfl.rb', line 5
def alias
@alias
end
|
#id ⇒ Object
Returns the value of attribute id.
5
6
7
|
# File 'lib/sportradar/api/football/nfl.rb', line 5
def id
@id
end
|
#name ⇒ Object
Returns the value of attribute name.
5
6
7
|
# File 'lib/sportradar/api/football/nfl.rb', line 5
def name
@name
end
|
#response ⇒ Object
Returns the value of attribute response.
5
6
7
|
# File 'lib/sportradar/api/football/nfl.rb', line 5
def response
@response
end
|
#season=(value) ⇒ Object
Sets the attribute season
5
6
7
|
# File 'lib/sportradar/api/football/nfl.rb', line 5
def season=(value)
@season = value
end
|
#type ⇒ Object
Returns the value of attribute type.
5
6
7
|
# File 'lib/sportradar/api/football/nfl.rb', line 5
def type
@type
end
|
Class Method Details
.sim_api ⇒ Object
def queue_venues
url, , options, timeout = api.get_request_info(path_venues)
{url: url, headers: , params: options, timeout: timeout, callback: method(:ingest_venues)}
end
.simulation ⇒ Object
291
292
293
|
# File 'lib/sportradar/api/football/nfl.rb', line 291
def self.simulation
new({}, api: sim_api, year: 2015, type: 'reg')
end
|
.simulations ⇒ Object
294
295
296
297
298
299
|
# File 'lib/sportradar/api/football/nfl.rb', line 294
def self.simulations
api = sim_api
['f45b4a31-b009-4039-8394-42efbc6d5532', '5a7042cb-fe7a-4838-b93f-6b8c167ec384', '7f761bb5-7963-43ea-a01b-baf4f5d50fe3'].map do |game_id|
Game.new({'id' => game_id}).sim!
end
end
|
Instance Method Details
#all_attributes ⇒ Object
6
7
8
|
# File 'lib/sportradar/api/football/nfl.rb', line 6
def all_attributes
[:name, :alias, :leagues, :divisions, :teams]
end
|
#conferences ⇒ Object
71
72
73
|
# File 'lib/sportradar/api/football/nfl.rb', line 71
def conferences
@conferences_hash.values
end
|
#default_date ⇒ Object
132
133
134
|
# File 'lib/sportradar/api/football/nfl.rb', line 132
def default_date
Date.today
end
|
#default_season ⇒ Object
135
136
137
|
# File 'lib/sportradar/api/football/nfl.rb', line 135
def default_season
'reg'
end
|
#default_year ⇒ Object
129
130
131
|
# File 'lib/sportradar/api/football/nfl.rb', line 129
def default_year
(Date.today - 60).year
end
|
#divisions ⇒ Object
def conference(code_name)
conferences_by_name[code_name]
end private def conferences_by_name
@conferences_by_name ||= conferences.map { |d| [d.alias, d] }.to_h
end
80
81
82
|
# File 'lib/sportradar/api/football/nfl.rb', line 80
def divisions
conferences.flat_map(&:divisions)
end
|
#games ⇒ Object
102
103
104
105
|
# File 'lib/sportradar/api/football/nfl.rb', line 102
def games
get_schedule if @weeks_hash.empty?
weeks.flat_map(&:games)
end
|
#get_depth_charts ⇒ Object
239
240
241
242
|
# File 'lib/sportradar/api/football/nfl.rb', line 239
def get_depth_charts
data = api.get_data(path_depth_charts).to_h
ingest_depth_charts(data)
end
|
#get_hierarchy ⇒ Object
222
223
224
225
|
# File 'lib/sportradar/api/football/nfl.rb', line 222
def get_hierarchy
data = api.get_data(path_hierarchy).to_h
ingest_hierarchy(data)
end
|
#get_schedule ⇒ Object
174
175
176
177
|
# File 'lib/sportradar/api/football/nfl.rb', line 174
def get_schedule
data = api.get_data(path_schedule).to_h
ingest_schedule(data)
end
|
#get_standings ⇒ Object
255
256
257
258
|
# File 'lib/sportradar/api/football/nfl.rb', line 255
def get_standings
data = api.get_data(path_standings).to_h
ingest_standings(data)
end
|
#get_weekly_schedule(nfl_season_week = 1) ⇒ Object
190
191
192
193
|
# File 'lib/sportradar/api/football/nfl.rb', line 190
def get_weekly_schedule(nfl_season_week = 1)
data = api.get_data(path_weekly_schedule(nfl_season_week)).to_h
ingest_weekly_schedule(data)
end
|
#hierarchy ⇒ Object
97
98
99
100
|
# File 'lib/sportradar/api/football/nfl.rb', line 97
def hierarchy
get_hierarchy if divisions.empty?
self
end
|
#ingest_depth_charts(data) ⇒ Object
244
245
246
247
|
# File 'lib/sportradar/api/football/nfl.rb', line 244
def ingest_depth_charts(data)
update(data, source: :teams)
data
end
|
#ingest_hierarchy(data) ⇒ Object
227
228
229
230
231
|
# File 'lib/sportradar/api/football/nfl.rb', line 227
def ingest_hierarchy(data)
update(data, source: :teams)
data
end
|
#ingest_schedule(data) ⇒ Object
179
180
181
182
|
# File 'lib/sportradar/api/football/nfl.rb', line 179
def ingest_schedule(data)
update(data, source: :weeks)
data
end
|
#ingest_standings(data) ⇒ Object
260
261
262
263
|
# File 'lib/sportradar/api/football/nfl.rb', line 260
def ingest_standings(data)
update(data, source: :teams)
data
end
|
#ingest_weekly_schedule(data) ⇒ Object
195
196
197
198
199
|
# File 'lib/sportradar/api/football/nfl.rb', line 195
def ingest_weekly_schedule(data)
create_data(@weeks_hash, data['week'], klass: Week, hierarchy: self, api: api)
data
end
|
#nfl_season ⇒ Object
Also known as:
season
142
143
144
|
# File 'lib/sportradar/api/football/nfl.rb', line 142
def nfl_season
@type || default_season
end
|
#path_base ⇒ Object
149
150
151
|
# File 'lib/sportradar/api/football/nfl.rb', line 149
def path_base
"league"
end
|
#path_hierarchy ⇒ Object
152
153
154
|
# File 'lib/sportradar/api/football/nfl.rb', line 152
def path_hierarchy
"league/hierarchy"
end
|
#path_schedule ⇒ Object
155
156
157
|
# File 'lib/sportradar/api/football/nfl.rb', line 155
def path_schedule
"games/#{season_year}/#{nfl_season}/schedule"
end
|
#path_standings ⇒ Object
167
168
169
|
# File 'lib/sportradar/api/football/nfl.rb', line 167
def path_standings
"seasons/#{season_year}/standings"
end
|
#path_weekly_depth_charts(nfl_season_week) ⇒ Object
161
162
163
|
# File 'lib/sportradar/api/football/nfl.rb', line 161
def path_weekly_depth_charts(nfl_season_week)
"seasons/#{season_year}/#{nfl_season}/#{nfl_season_week}/depth_charts"
end
|
#path_weekly_depth_injuries(nfl_season_week) ⇒ Object
164
165
166
|
# File 'lib/sportradar/api/football/nfl.rb', line 164
def path_weekly_depth_injuries(nfl_season_week)
"seasons/#{season_year}/#{nfl_season}/#{nfl_season_week}/injuries"
end
|
#path_weekly_schedule(nfl_season_week) ⇒ Object
158
159
160
|
# File 'lib/sportradar/api/football/nfl.rb', line 158
def path_weekly_schedule(nfl_season_week)
"games/#{season_year}/#{nfl_season}/#{nfl_season_week}/schedule"
end
|
#queue_depth_charts ⇒ Object
249
250
251
252
|
# File 'lib/sportradar/api/football/nfl.rb', line 249
def queue_depth_charts
url, , options, timeout = api.get_request_info(path_depth_charts)
{url: url, headers: , params: options, timeout: timeout, callback: method(:ingest_depth_charts)}
end
|
#queue_hierarchy ⇒ Object
233
234
235
236
|
# File 'lib/sportradar/api/football/nfl.rb', line 233
def queue_hierarchy
url, , options, timeout = api.get_request_info(path_hierarchy)
{url: url, headers: , params: options, timeout: timeout, callback: method(:ingest_hierarchy)}
end
|
#queue_schedule ⇒ Object
184
185
186
187
|
# File 'lib/sportradar/api/football/nfl.rb', line 184
def queue_schedule
url, , options, timeout = api.get_request_info(path_schedule)
{url: url, headers: , params: options, timeout: timeout, callback: method(:ingest_schedule)}
end
|
#queue_standings ⇒ Object
265
266
267
268
|
# File 'lib/sportradar/api/football/nfl.rb', line 265
def queue_standings
url, , options, timeout = api.get_request_info(path_standings)
{url: url, headers: , params: options, timeout: timeout, callback: method(:ingest_standings)}
end
|
#queue_weekly_schedule(nfl_season_week = 1) ⇒ Object
201
202
203
204
|
# File 'lib/sportradar/api/football/nfl.rb', line 201
def queue_weekly_schedule(nfl_season_week = 1)
url, , options, timeout = api.get_request_info(path_weekly_schedule(nfl_season_week))
{url: url, headers: , params: options, timeout: timeout, callback: method(:ingest_weekly_schedule)}
end
|
#schedule ⇒ Object
87
88
89
90
|
# File 'lib/sportradar/api/football/nfl.rb', line 87
def schedule
get_schedule if games.empty?
self
end
|
#season_year ⇒ Object
Also known as:
year
138
139
140
|
# File 'lib/sportradar/api/football/nfl.rb', line 138
def season_year
@season || default_year
end
|
#standings ⇒ Object
92
93
94
95
|
# File 'lib/sportradar/api/football/nfl.rb', line 92
def standings
get_standings if divisions.empty? || teams.first&.record.nil?
self
end
|
#team(team_id) ⇒ Object
120
121
122
|
# File 'lib/sportradar/api/football/nfl.rb', line 120
def team(team_id)
teams.detect { |team| team.id == team_id }
end
|
#teams ⇒ Object
83
84
85
|
# File 'lib/sportradar/api/football/nfl.rb', line 83
def teams
divisions.flat_map(&:teams)
end
|
#update(data, source: nil, **opts) ⇒ Object
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
|
# File 'lib/sportradar/api/football/nfl.rb', line 26
def update(data, source: nil, **opts)
@id = data['id'] if data['id']
if data['season'].is_a?(Hash)
@season = data.dig('season', 'year') if data.dig('season', 'year')
@type = data.dig('season', 'type') if data.dig('season', 'type')
else
@season = data['season'] if data['season']
@type = data['type'] if data['type']
end
create_data(@conferences_hash, data['conferences'], klass: Conference, hierarchy: self, api: api) if data['conferences']
create_data(@teams_hash, data['teams'], klass: Team, hierarchy: self, api: api) if data['teams']
if data['weeks']
create_data(@weeks_hash, data['weeks'], klass: Week, hierarchy: self, api: @api)
end
if data['league']
@id = data['id']
@name = data['name']
@alias = data['alias']
end
if data['games']
if data['games'].first.keys == ['game']
data['games'].map! { |hash| hash['game'] }
end
create_data(@games_hash, data['games'], klass: Game, hierarchy: self, api: api)
end
self
end
|
#weekly_depth_charts(week_number) ⇒ Object
64
65
66
|
# File 'lib/sportradar/api/football/nfl.rb', line 64
def weekly_depth_charts(week_number)
@depth_charts_hash[week_number] ||= get_weekly_depth_charts(week_number)
end
|
#weeks ⇒ Object
68
69
70
|
# File 'lib/sportradar/api/football/nfl.rb', line 68
def weeks
@weeks_hash.values
end
|