Class: Sportradar::Api::Football::Ncaafb

Inherits:
Data
  • Object
show all
Defined in:
lib/sportradar/api/football/ncaafb.rb,
lib/sportradar/api/football/ncaafb/api.rb,
lib/sportradar/api/football/ncaafb/game.rb,
lib/sportradar/api/football/ncaafb/play.rb,
lib/sportradar/api/football/ncaafb/team.rb,
lib/sportradar/api/football/ncaafb/week.rb,
lib/sportradar/api/football/ncaafb/drive.rb,
lib/sportradar/api/football/ncaafb/player.rb,
lib/sportradar/api/football/ncaafb/quarter.rb,
lib/sportradar/api/football/ncaafb/division.rb,
lib/sportradar/api/football/ncaafb/conference.rb,
lib/sportradar/api/football/ncaafb/subdivision.rb

Defined Under Namespace

Classes: Api, Conference, Division, Drive, Game, Play, Player, Quarter, Subdivision, Team, 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) ⇒ Ncaafb

Returns a new instance of Ncaafb.



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/sportradar/api/football/ncaafb.rb', line 10

def initialize(data = {}, **opts)
  # @response = data
  @api  = opts[:api]
  @id   = data['id']
  @season = opts[:year]
  @type   = opts[:type]

  @divisions_hash = {}
  @weeks_hash = {}
  @games_hash = {}
  @teams_hash = {}

end

Instance Attribute Details

#aliasObject

Returns the value of attribute alias.



5
6
7
# File 'lib/sportradar/api/football/ncaafb.rb', line 5

def alias
  @alias
end

#idObject

Returns the value of attribute id.



5
6
7
# File 'lib/sportradar/api/football/ncaafb.rb', line 5

def id
  @id
end

#nameObject

Returns the value of attribute name.



5
6
7
# File 'lib/sportradar/api/football/ncaafb.rb', line 5

def name
  @name
end

#responseObject

Returns the value of attribute response.



5
6
7
# File 'lib/sportradar/api/football/ncaafb.rb', line 5

def response
  @response
end

#typeObject

Returns the value of attribute type.



5
6
7
# File 'lib/sportradar/api/football/ncaafb.rb', line 5

def type
  @type
end

Class Method Details

.sim_apiObject

def queue_venues

url, headers, options, timeout = api.get_request_info(path_venues)
{url: url, headers: headers, params: options, timeout: timeout, callback: method(:ingest_venues)}

end



247
248
249
# File 'lib/sportradar/api/football/ncaafb.rb', line 247

def self.sim_api
  Sportradar::Api::Football::Ncaafb::Api.new.sim!
end

.simulationObject



250
251
252
# File 'lib/sportradar/api/football/ncaafb.rb', line 250

def self.simulation
  new({}, api: sim_api, year: 2015, type: 'reg')
end

.simulationsObject



253
254
255
256
257
258
# File 'lib/sportradar/api/football/ncaafb.rb', line 253

def self.simulations
  api = sim_api
  ['2015/REG/1/WKY/MSH', '2015/REG/1/KEN/FLA', '2015/REG/1/WOU/PRST'].map do |game_uri|
    Game.new({'id' => game_uri}).sim!
  end
end

Instance Method Details

#all_attributesObject



6
7
8
# File 'lib/sportradar/api/football/ncaafb.rb', line 6

def all_attributes
  [:name, :alias, :leagues, :divisions, :teams]
end

#apiObject

api stuff



103
104
105
# File 'lib/sportradar/api/football/ncaafb.rb', line 103

def api
  @api || Sportradar::Api::Football::Ncaafb::Api.new
end

#conferencesObject



62
63
64
# File 'lib/sportradar/api/football/ncaafb.rb', line 62

def conferences
  divisions.flat_map(&:conferences)
end

#default_dateObject



110
111
112
# File 'lib/sportradar/api/football/ncaafb.rb', line 110

def default_date
  Date.today
end

#default_seasonObject



113
114
115
# File 'lib/sportradar/api/football/ncaafb.rb', line 113

def default_season
  'reg'
end

#default_yearObject



107
108
109
# File 'lib/sportradar/api/football/ncaafb.rb', line 107

def default_year
  (Date.today - 60).year
end

#division(code_name) ⇒ Object



56
57
58
# File 'lib/sportradar/api/football/ncaafb.rb', line 56

def division(code_name)
  divisions_by_name[code_name]
end

#divisionsObject



53
54
55
# File 'lib/sportradar/api/football/ncaafb.rb', line 53

def divisions
  @divisions_hash.values
end

#gamesObject



81
82
83
84
# File 'lib/sportradar/api/football/ncaafb.rb', line 81

def games
  get_schedule if @weeks_hash.empty?
  weeks.flat_map(&:games)
end

#get_depth_chartsObject

depth_charts



198
199
200
201
# File 'lib/sportradar/api/football/ncaafb.rb', line 198

def get_depth_charts
  data = api.get_data(path_depth_charts).to_h
  ingest_depth_charts(data)
end

#get_hierarchy(division = 'FBS') ⇒ Object

hierarchy



182
183
184
185
# File 'lib/sportradar/api/football/ncaafb.rb', line 182

def get_hierarchy(division = 'FBS')
  data = api.get_data(path_hierarchy(division)).to_h
  ingest_hierarchy(data)
end

#get_scheduleObject

schedule



149
150
151
152
# File 'lib/sportradar/api/football/ncaafb.rb', line 149

def get_schedule
  data = api.get_data(path_schedule).to_h
  ingest_schedule(data)
end

#get_standings(division = 'FBS') ⇒ Object

standings



214
215
216
217
# File 'lib/sportradar/api/football/ncaafb.rb', line 214

def get_standings(division = 'FBS')
  data = api.get_data(path_standings(division)).to_h
  ingest_standings(data)
end

#get_weekly_schedule(ncaafb_season_week = 1) ⇒ Object

weekly schedule



165
166
167
168
# File 'lib/sportradar/api/football/ncaafb.rb', line 165

def get_weekly_schedule(ncaafb_season_week = 1)
  data = api.get_data(path_weekly_schedule(ncaafb_season_week)).to_h
  ingest_weekly_schedule(data)
end

#hierarchyObject



76
77
78
79
# File 'lib/sportradar/api/football/ncaafb.rb', line 76

def hierarchy
  get_hierarchy if divisions.empty?
  self
end

#ingest_depth_charts(data) ⇒ Object



203
204
205
206
# File 'lib/sportradar/api/football/ncaafb.rb', line 203

def ingest_depth_charts(data)
  update(data, source: :teams)
  data
end

#ingest_hierarchy(data) ⇒ Object



187
188
189
190
# File 'lib/sportradar/api/football/ncaafb.rb', line 187

def ingest_hierarchy(data)
  create_data(@divisions_hash, data, klass: Division,  hierarchy: self, api: api)
  data
end

#ingest_schedule(data) ⇒ Object



154
155
156
157
# File 'lib/sportradar/api/football/ncaafb.rb', line 154

def ingest_schedule(data)
  update(data, source: :weeks)
  data
end

#ingest_standings(data) ⇒ Object



219
220
221
222
# File 'lib/sportradar/api/football/ncaafb.rb', line 219

def ingest_standings(data)
  update(data, source: :teams)
  data
end

#ingest_weekly_schedule(data) ⇒ Object



170
171
172
173
174
# File 'lib/sportradar/api/football/ncaafb.rb', line 170

def ingest_weekly_schedule(data)
  # update(data, source: :weeks)
  create_data(@weeks_hash, data, klass: Week, hierarchy: self, api: api)
  data
end

#ncaafb_seasonObject Also known as: season



120
121
122
# File 'lib/sportradar/api/football/ncaafb.rb', line 120

def ncaafb_season
  @type || default_season
end

#path_baseObject

url paths



127
128
129
# File 'lib/sportradar/api/football/ncaafb.rb', line 127

def path_base
  "league"
end

#path_hierarchy(division = 'FBS') ⇒ Object



130
131
132
# File 'lib/sportradar/api/football/ncaafb.rb', line 130

def path_hierarchy(division = 'FBS')
  "teams/#{division}/hierarchy"
end

#path_rankings(ncaafb_season_week, poll_name = 'AP25') ⇒ Object



139
140
141
# File 'lib/sportradar/api/football/ncaafb.rb', line 139

def path_rankings(ncaafb_season_week, poll_name = 'AP25')
  "polls/#{poll_name}/#{season_year}/#{ncaafb_season_week}/rankings"
end

#path_scheduleObject



133
134
135
# File 'lib/sportradar/api/football/ncaafb.rb', line 133

def path_schedule
  "#{season_year}/#{ncaafb_season}/schedule"
end

#path_standings(division = 'FBS') ⇒ Object



142
143
144
# File 'lib/sportradar/api/football/ncaafb.rb', line 142

def path_standings(division = 'FBS')
  "teams/#{division}/#{season_year}/#{ncaafb_season}/standings"
end

#path_weekly_schedule(ncaafb_season_week) ⇒ Object



136
137
138
# File 'lib/sportradar/api/football/ncaafb.rb', line 136

def path_weekly_schedule(ncaafb_season_week)
  "#{season_year}/#{ncaafb_season}/#{ncaafb_season_week}/schedule"
end

#queue_depth_chartsObject



208
209
210
211
# File 'lib/sportradar/api/football/ncaafb.rb', line 208

def queue_depth_charts
  url, headers, options, timeout = api.get_request_info(path_depth_charts)
  {url: url, headers: headers, params: options, timeout: timeout, callback: method(:ingest_depth_charts)}
end

#queue_hierarchyObject



192
193
194
195
# File 'lib/sportradar/api/football/ncaafb.rb', line 192

def queue_hierarchy
  url, headers, options, timeout = api.get_request_info(path_hierarchy)
  {url: url, headers: headers, params: options, timeout: timeout, callback: method(:ingest_hierarchy)}
end

#queue_scheduleObject



159
160
161
162
# File 'lib/sportradar/api/football/ncaafb.rb', line 159

def queue_schedule
  url, headers, options, timeout = api.get_request_info(path_schedule)
  {url: url, headers: headers, params: options, timeout: timeout, callback: method(:ingest_schedule)}
end

#queue_standingsObject



224
225
226
227
# File 'lib/sportradar/api/football/ncaafb.rb', line 224

def queue_standings
  url, headers, options, timeout = api.get_request_info(path_standings)
  {url: url, headers: headers, params: options, timeout: timeout, callback: method(:ingest_standings)}
end

#queue_weekly_schedule(ncaafb_season_week = 1) ⇒ Object



176
177
178
179
# File 'lib/sportradar/api/football/ncaafb.rb', line 176

def queue_weekly_schedule(ncaafb_season_week = 1)
  url, headers, options, timeout = api.get_request_info(path_weekly_schedule(ncaafb_season_week))
  {url: url, headers: headers, params: options, timeout: timeout, callback: method(:ingest_weekly_schedule)}
end

#scheduleObject



66
67
68
69
# File 'lib/sportradar/api/football/ncaafb.rb', line 66

def schedule
  get_schedule if games.empty?
  self
end

#season_yearObject Also known as: year



116
117
118
# File 'lib/sportradar/api/football/ncaafb.rb', line 116

def season_year
  @season || default_year
end

#standingsObject



71
72
73
74
# File 'lib/sportradar/api/football/ncaafb.rb', line 71

def standings
  get_standings if divisions.empty? || teams.first&.record.nil?
  self
end

#team(team_id) ⇒ Object



98
99
100
# File 'lib/sportradar/api/football/ncaafb.rb', line 98

def team(team_id)
  teams.detect { |team| team.id == team_id }
end

#teamsObject



85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/sportradar/api/football/ncaafb.rb', line 85

def teams
  teams = conferences.flat_map(&:teams)
  if teams.empty?
    if @teams_hash.empty?
      get_hierarchy
      conferences.flat_map(&:teams)
    else
      @teams_hash.values
    end
  else
    teams
  end
end

#update(data, source: nil, **opts) ⇒ Object



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
# File 'lib/sportradar/api/football/ncaafb.rb', line 24

def update(data, source: nil, **opts)
  # update stuff
  @id     = data['id'] if data['id']
  @season = data['season']  if data['season']
  @type   = data['type']    if data['type']
  # @name     = data.dig('league', 'name')  if data.dig('league', 'name')
  # @alias    = data.dig('league', 'alias') if data.dig('league', 'alias')

  # @year     = data.dig('season', 'year')  if data.dig('season', 'year')
  # @type     = data.dig('season', 'type')  if data.dig('season', 'type')

  create_data(@divisions_hash, data['divisions'], klass: Division,  hierarchy: self, api: api) if data['divisions']
  create_data(@divisions_hash, data['division'], klass: Division,  hierarchy: self, api: api) if data['division']
  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['games']
    if data['games'].first.keys == ['game']
      data['games'].map! { |hash| hash['game'] }
    end
    @games_hash = create_data(@games_hash, data['games'],   klass: Game,   hierarchy: self, api: api)
  end
end

#weeksObject



50
51
52
# File 'lib/sportradar/api/football/ncaafb.rb', line 50

def weeks
  @weeks_hash.values
end