Class: Sportradar::Api::Basketball::Team
- Inherits:
-
Data
- Object
- Data
- Sportradar::Api::Basketball::Team
show all
- Defined in:
- lib/sportradar/api/basketball/team.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods inherited from Data
#all_attributes, #attributes, #create_data, #parse_into_array, #parse_into_array_with_options, #parse_out_hashes, #structure_links, #update_data
Constructor Details
#initialize(data, **opts) ⇒ Team
Returns a new instance of Team.
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/sportradar/api/basketball/team.rb', line 7
def initialize(data, **opts)
@response = data
@api = opts[:api]
@games_hash = {}
@players_hash = {}
@player_stats = {}
@records = {}
@stats = nil
@points = nil
case data
when String
@id = data
when Hash
@id = data['id']
update(data, **opts)
end
end
|
Instance Attribute Details
#alias ⇒ Object
Returns the value of attribute alias.
5
6
7
|
# File 'lib/sportradar/api/basketball/team.rb', line 5
def alias
@alias
end
|
#full_name ⇒ Object
Returns the value of attribute full_name.
5
6
7
|
# File 'lib/sportradar/api/basketball/team.rb', line 5
def full_name
@full_name
end
|
#id ⇒ Object
Returns the value of attribute id.
5
6
7
|
# File 'lib/sportradar/api/basketball/team.rb', line 5
def id
@id
end
|
#market ⇒ Object
Returns the value of attribute market.
5
6
7
|
# File 'lib/sportradar/api/basketball/team.rb', line 5
def market
@market
end
|
#name ⇒ Object
Returns the value of attribute name.
5
6
7
|
# File 'lib/sportradar/api/basketball/team.rb', line 5
def name
@name
end
|
#player_stats ⇒ Object
Returns the value of attribute player_stats.
5
6
7
|
# File 'lib/sportradar/api/basketball/team.rb', line 5
def player_stats
@player_stats
end
|
#records ⇒ Object
Returns the value of attribute records.
5
6
7
|
# File 'lib/sportradar/api/basketball/team.rb', line 5
def records
@records
end
|
#response ⇒ Object
Returns the value of attribute response.
5
6
7
|
# File 'lib/sportradar/api/basketball/team.rb', line 5
def response
@response
end
|
#seed ⇒ Object
Returns the value of attribute seed.
5
6
7
|
# File 'lib/sportradar/api/basketball/team.rb', line 5
def seed
@seed
end
|
#team_stats ⇒ Object
Returns the value of attribute team_stats.
5
6
7
|
# File 'lib/sportradar/api/basketball/team.rb', line 5
def team_stats
@team_stats
end
|
#venue ⇒ Object
Returns the value of attribute venue.
5
6
7
|
# File 'lib/sportradar/api/basketball/team.rb', line 5
def venue
@venue
end
|
Instance Method Details
#add_game(game) ⇒ Object
70
71
72
|
# File 'lib/sportradar/api/basketball/team.rb', line 70
def add_game(game)
@games_hash[game.id] = game.id if game
end
|
#games ⇒ Object
67
68
69
|
# File 'lib/sportradar/api/basketball/team.rb', line 67
def games
@games_hash.values
end
|
#get_roster ⇒ Object
105
106
107
108
|
# File 'lib/sportradar/api/basketball/team.rb', line 105
def get_roster
data = api.get_data(path_roster).to_h
ingest_roster(data)
end
|
#get_season_stats(year = api.default_year) ⇒ Object
118
119
120
121
|
# File 'lib/sportradar/api/basketball/team.rb', line 118
def get_season_stats(year = api.default_year)
data = api.get_data(path_season_stats(year)).to_h
ingest_season_stats(data)
end
|
#handle_names(data) ⇒ Object
52
53
54
55
56
57
58
59
60
61
|
# File 'lib/sportradar/api/basketball/team.rb', line 52
def handle_names(data)
@name = data['name'] if data['name']
if data['name'] && !data.key?('market')
@full_name = data['name']
elsif data['name'] && data['market']
@market = data['market']
@full_name = [@market, data['name']].join(' ')
end
end
|
#ingest_roster(data) ⇒ Object
109
110
111
112
|
# File 'lib/sportradar/api/basketball/team.rb', line 109
def ingest_roster(data)
update(data)
data
end
|
#ingest_season_stats(data) ⇒ Object
122
123
124
|
# File 'lib/sportradar/api/basketball/team.rb', line 122
def ingest_season_stats(data)
parse_season_stats(data)
end
|
#parse_players(data, game) ⇒ Object
83
84
85
|
# File 'lib/sportradar/api/basketball/team.rb', line 83
def parse_players(data, game)
create_data(@players_hash, data, klass: player_class, api: api, team: self, game: game)
end
|
#parse_records(data) ⇒ Object
89
90
91
92
|
# File 'lib/sportradar/api/basketball/team.rb', line 89
def parse_records(data)
@records['overall'] = Record.new(data, type: 'overall')
data['records'].each { |record| @records[record['record_type']] = Record.new(record, type: record['record_type']) }
end
|
#parse_season_stats(data) ⇒ Object
94
95
96
97
98
99
100
|
# File 'lib/sportradar/api/basketball/team.rb', line 94
def parse_season_stats(data)
@team_stats = data.dig('own_record')
update(data)
player_data = data.dig('players')
create_data(@players_hash, player_data, klass: player_class, api: api, team: self)
data
end
|
#path_base ⇒ Object
131
132
133
|
# File 'lib/sportradar/api/basketball/team.rb', line 131
def path_base
"teams/#{ id }"
end
|
#path_base_stats(season_year = api.default_year, default_season = api.default_season) ⇒ Object
134
135
136
|
# File 'lib/sportradar/api/basketball/team.rb', line 134
def path_base_stats(season_year = api.default_year, default_season = api.default_season)
"seasons/#{season_year}/#{default_season}/teams/#{id}"
end
|
#path_roster ⇒ Object
137
138
139
|
# File 'lib/sportradar/api/basketball/team.rb', line 137
def path_roster
"#{ path_base }/profile"
end
|
#path_season_stats(year) ⇒ Object
140
141
142
|
# File 'lib/sportradar/api/basketball/team.rb', line 140
def path_season_stats(year)
"#{ path_base_stats(year) }/statistics"
end
|
#players ⇒ Object
Also known as:
roster
def parse_stats(data)
@stats = data
end
78
79
80
81
|
# File 'lib/sportradar/api/basketball/team.rb', line 78
def players
get_roster if @players_hash.empty?
@players_hash.values
end
|
#profile ⇒ Object
27
28
29
|
# File 'lib/sportradar/api/basketball/team.rb', line 27
def profile
Profile.new(self)
end
|
#queue_roster ⇒ Object
113
114
115
116
|
# File 'lib/sportradar/api/basketball/team.rb', line 113
def queue_roster
url, , options, timeout = api.get_request_info(path_roster)
{url: url, headers: , params: options, timeout: timeout, callback: method(:ingest_roster)}
end
|
#queue_season_stats ⇒ Object
125
126
127
128
|
# File 'lib/sportradar/api/basketball/team.rb', line 125
def queue_season_stats
url, , options, timeout = api.get_request_info(path_season_stats)
{url: url, headers: , params: options, timeout: timeout, callback: method(:ingest_season_stats)}
end
|
#record(type = 'overall') ⇒ Object
63
64
65
|
# File 'lib/sportradar/api/basketball/team.rb', line 63
def record(type = 'overall')
@records[type]
end
|
#update(data, **opts) ⇒ Object
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/sportradar/api/basketball/team.rb', line 31
def update(data, **opts)
handle_names(data)
@venue = Venue.new(data['venue']) if data['venue']
@seed = data['seed'].to_i if data['seed']
@alias = data['alias'] if data['alias']
@points = data['points'].to_i if data['points']
parse_records(data) if data['records']
parse_players(data.dig('players'), opts[:game]) if data.dig('players')
if opts[:game]
add_game(opts[:game])
opts[:game].update_score(id => @points) if @points
opts[:game].update_stats(self, data['statistics']) if data['statistics']
end
end
|
#update_player_stats(player, stats, game = nil) ⇒ Object
86
87
88
|
# File 'lib/sportradar/api/basketball/team.rb', line 86
def update_player_stats(player, stats, game = nil)
game ? game.update_player_stats(player, stats) : @player_stats.merge!(player.id => stats.merge(player: player))
end
|