Class: Sportradar::Api::Basketball::Ncaamb

Inherits:
Data
  • Object
show all
Defined in:
lib/sportradar/api/basketball/ncaamb.rb,
lib/sportradar/api/basketball/ncaamb/api.rb,
lib/sportradar/api/basketball/ncaamb/game.rb,
lib/sportradar/api/basketball/ncaamb/half.rb,
lib/sportradar/api/basketball/ncaamb/team.rb,
lib/sportradar/api/basketball/ncaamb/round.rb,
lib/sportradar/api/basketball/ncaamb/player.rb,
lib/sportradar/api/basketball/ncaamb/season.rb,
lib/sportradar/api/basketball/ncaamb/bracket.rb,
lib/sportradar/api/basketball/ncaamb/division.rb,
lib/sportradar/api/basketball/ncaamb/schedule.rb,
lib/sportradar/api/basketball/ncaamb/hierarchy.rb,
lib/sportradar/api/basketball/ncaamb/conference.rb,
lib/sportradar/api/basketball/ncaamb/tournament.rb

Defined Under Namespace

Classes: Api, Bracket, Conference, Division, Game, Half, Hierarchy, Player, Round, Schedule, Season, Team, Tournament

Instance Attribute 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) ⇒ Ncaamb

Returns a new instance of Ncaamb.



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

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

  @divisions_hash     = create_data({}, {"id" => "c5a8d640-5093-4044-851d-2c562e929994", "name" => "NCAA Division I", "alias" => "D1"}, klass: Division, api: api)
  @weeks_hash         = {}
  @games_hash         = {}
  @tournaments_hash   = {}
  @teams_hash         = {}

  update(data, **opts)
end

Instance Attribute Details

#aliasObject

Returns the value of attribute alias.



5
6
7
# File 'lib/sportradar/api/basketball/ncaamb.rb', line 5

def alias
  @alias
end

#idObject

Returns the value of attribute id.



5
6
7
# File 'lib/sportradar/api/basketball/ncaamb.rb', line 5

def id
  @id
end

#nameObject

Returns the value of attribute name.



5
6
7
# File 'lib/sportradar/api/basketball/ncaamb.rb', line 5

def name
  @name
end

#responseObject

Returns the value of attribute response.



5
6
7
# File 'lib/sportradar/api/basketball/ncaamb.rb', line 5

def response
  @response
end

Instance Method Details

#all_attributesObject



6
7
8
# File 'lib/sportradar/api/basketball/ncaamb.rb', line 6

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

#apiObject



167
168
169
# File 'lib/sportradar/api/basketball/ncaamb.rb', line 167

def api
  @api || Sportradar::Api::Basketball::Ncaamb::Api.new
end

#conferencesObject



58
59
60
# File 'lib/sportradar/api/basketball/ncaamb.rb', line 58

def conferences
  divisions.flat_map(&:conferences)
end

#default_dateObject



174
175
176
# File 'lib/sportradar/api/basketball/ncaamb.rb', line 174

def default_date
  Date.today
end

#default_seasonObject



177
178
179
# File 'lib/sportradar/api/basketball/ncaamb.rb', line 177

def default_season
  'reg'
end

#default_yearObject



171
172
173
# File 'lib/sportradar/api/basketball/ncaamb.rb', line 171

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

#division(code_name) ⇒ Object



52
53
54
# File 'lib/sportradar/api/basketball/ncaamb.rb', line 52

def division(code_name)
  divisions_by_name[code_name]
end

#divisionsObject



49
50
51
# File 'lib/sportradar/api/basketball/ncaamb.rb', line 49

def divisions
  @divisions_hash.values
end

#gamesObject



82
83
84
# File 'lib/sportradar/api/basketball/ncaamb.rb', line 82

def games
  @games_hash.values
end

#get_conference_tournamentsObject



122
123
124
125
# File 'lib/sportradar/api/basketball/ncaamb.rb', line 122

def get_conference_tournaments
  data = api.get_data(path_conference_tournaments).to_h
  ingest_conference_tournaments(data)
end

#get_daily_schedule(date = default_date) ⇒ Object



131
132
133
134
# File 'lib/sportradar/api/basketball/ncaamb.rb', line 131

def get_daily_schedule(date = default_date)
  data = api.get_data(path_daily_schedule(date)).to_h
  ingest_daily_schedule(data)
end

#get_hierarchyObject



149
150
151
152
# File 'lib/sportradar/api/basketball/ncaamb.rb', line 149

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

#get_rankings(poll_name, ncaamb_week = nil) ⇒ Object



140
141
142
143
# File 'lib/sportradar/api/basketball/ncaamb.rb', line 140

def get_rankings(poll_name, ncaamb_week = nil)
  data = api.get_data(path_rankings(poll_name, ncaamb_week)).to_h
  ingest_rankings(data)
end

#get_scheduleObject



104
105
106
107
# File 'lib/sportradar/api/basketball/ncaamb.rb', line 104

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

#get_standingsObject



158
159
160
161
# File 'lib/sportradar/api/basketball/ncaamb.rb', line 158

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

#get_tournaments(tourney_season = 'pst') ⇒ Object



113
114
115
116
# File 'lib/sportradar/api/basketball/ncaamb.rb', line 113

def get_tournaments(tourney_season = 'pst')
  data = api.get_data(path_tournaments(tourney_season)).to_h
  ingest_tournaments(data)
end

#hierarchyObject



72
73
74
75
# File 'lib/sportradar/api/basketball/ncaamb.rb', line 72

def hierarchy
  get_hierarchy if divisions.empty?
  self
end

#ingest_conference_tournaments(data) ⇒ Object



126
127
128
129
# File 'lib/sportradar/api/basketball/ncaamb.rb', line 126

def ingest_conference_tournaments(data)
  update(data)
  data
end

#ingest_daily_schedule(data) ⇒ Object



135
136
137
138
# File 'lib/sportradar/api/basketball/ncaamb.rb', line 135

def ingest_daily_schedule(data)
  update(data)
  data
end

#ingest_hierarchy(data) ⇒ Object



153
154
155
156
# File 'lib/sportradar/api/basketball/ncaamb.rb', line 153

def ingest_hierarchy(data)
  update(data)
  data
end

#ingest_rankings(data) ⇒ Object



144
145
146
147
# File 'lib/sportradar/api/basketball/ncaamb.rb', line 144

def ingest_rankings(data)
  update(data)
  data
end

#ingest_schedule(data) ⇒ Object



108
109
110
111
# File 'lib/sportradar/api/basketball/ncaamb.rb', line 108

def ingest_schedule(data)
  update(data)
  data
end

#ingest_standings(data) ⇒ Object



162
163
164
165
# File 'lib/sportradar/api/basketball/ncaamb.rb', line 162

def ingest_standings(data)
  division('D1').update(data)
  data
end

#ingest_tournaments(data) ⇒ Object



117
118
119
120
# File 'lib/sportradar/api/basketball/ncaamb.rb', line 117

def ingest_tournaments(data)
  update(data)
  data
end

#ncaamb_seasonObject Also known as: season



184
185
186
# File 'lib/sportradar/api/basketball/ncaamb.rb', line 184

def ncaamb_season
  @type || default_season
end

#path_conference_tournamentsObject



197
198
199
# File 'lib/sportradar/api/basketball/ncaamb.rb', line 197

def path_conference_tournaments
  path_tournaments('ct')
end

#path_daily_schedule(date = default_date) ⇒ Object



201
202
203
# File 'lib/sportradar/api/basketball/ncaamb.rb', line 201

def path_daily_schedule(date = default_date)
  "games/#{ date.year }/#{ date.month }/#{ date.day }/schedule"
end

#path_hierarchyObject



209
210
211
# File 'lib/sportradar/api/basketball/ncaamb.rb', line 209

def path_hierarchy
  "league/hierarchy"
end

#path_rankings(poll_name, ncaamb_week = nil, season_year = default_year) ⇒ Object



205
206
207
# File 'lib/sportradar/api/basketball/ncaamb.rb', line 205

def path_rankings(poll_name, ncaamb_week = nil, season_year = default_year)
  "polls/#{poll_name}/#{season_year}/#{ncaamb_week}/rankings"
end

#path_scheduleObject



189
190
191
# File 'lib/sportradar/api/basketball/ncaamb.rb', line 189

def path_schedule
  "games/#{season_year}/#{ncaamb_season}/schedule"
end

#path_standingsObject



213
214
215
# File 'lib/sportradar/api/basketball/ncaamb.rb', line 213

def path_standings
  "seasontd/#{season_year}/#{ncaamb_season}/standings"
end

#path_tournaments(tourney_season = 'pst') ⇒ Object



193
194
195
# File 'lib/sportradar/api/basketball/ncaamb.rb', line 193

def path_tournaments(tourney_season = 'pst')
  "tournaments/#{season_year}/#{tourney_season}/schedule"
end

#scheduleObject



62
63
64
65
# File 'lib/sportradar/api/basketball/ncaamb.rb', line 62

def schedule
  get_schedule if games.empty?
  self
end

#season_yearObject Also known as: year



180
181
182
# File 'lib/sportradar/api/basketball/ncaamb.rb', line 180

def season_year
  @season || default_year
end

#standingsObject



67
68
69
70
# File 'lib/sportradar/api/basketball/ncaamb.rb', line 67

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

#team(team_id) ⇒ Object



100
101
102
# File 'lib/sportradar/api/basketball/ncaamb.rb', line 100

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

#teamsObject



86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/sportradar/api/basketball/ncaamb.rb', line 86

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

#tournamentsObject



77
78
79
80
# File 'lib/sportradar/api/basketball/ncaamb.rb', line 77

def tournaments
  get_tournaments if @tournaments_hash.empty?
  @tournaments_hash.values
end

#update(data, **opts) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/sportradar/api/basketball/ncaamb.rb', line 26

def update(data, **opts)
  @id     = data['id'] if data['id']

  if data['league']
    @id    = data.dig('league', 'id')
    @name  = data.dig('league', 'name')
    @alias = data.dig('league', 'alias')
  end

  if data['season'].is_a?(Hash)
    @season   = data.dig('season', 'year')
    @type     = data.dig('season', 'type')
  else
    @season = data['season']  if data['season']
    @type   = data['type']    if data['type']
  end

  create_data(@teams_hash,        data['teams'],        klass: Team,        api: api) if data['teams']
  create_data(@divisions_hash,    data['divisions'],    klass: Division,    api: api) if data['divisions']
  create_data(@games_hash,        data['games'],        klass: Game,        api: api) if data['games']
  create_data(@tournaments_hash,  data['tournaments'],  klass: Tournament,  api: api) if data['tournaments']
end