Class: Sportradar::Api::Baseball::Team
- Inherits:
-
Data
- Object
- Data
- Sportradar::Api::Baseball::Team
show all
- Defined in:
- lib/sportradar/api/baseball/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
|
# File 'lib/sportradar/api/baseball/team.rb', line 7
def initialize(data, **opts)
@response = data @api = opts[:api]
@id = data['id']
@games_hash = {}
@players_hash = {}
@player_stats = {}
@records = {}
@stats = nil
@runs = nil
update(data, **opts)
end
|
Instance Attribute Details
#alias ⇒ Object
Returns the value of attribute alias.
5
6
7
|
# File 'lib/sportradar/api/baseball/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/baseball/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/baseball/team.rb', line 5
def id
@id
end
|
#market ⇒ Object
Returns the value of attribute market.
5
6
7
|
# File 'lib/sportradar/api/baseball/team.rb', line 5
def market
@market
end
|
#name ⇒ Object
Returns the value of attribute name.
5
6
7
|
# File 'lib/sportradar/api/baseball/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/baseball/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/baseball/team.rb', line 5
def records
@records
end
|
#response ⇒ Object
Returns the value of attribute response.
5
6
7
|
# File 'lib/sportradar/api/baseball/team.rb', line 5
def response
@response
end
|
#team_stats ⇒ Object
Returns the value of attribute team_stats.
5
6
7
|
# File 'lib/sportradar/api/baseball/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/baseball/team.rb', line 5
def venue
@venue
end
|
Instance Method Details
#add_game(game) ⇒ Object
67
68
69
|
# File 'lib/sportradar/api/baseball/team.rb', line 67
def add_game(game)
@games_hash[game.id] = game.id if game
end
|
#games ⇒ Object
64
65
66
|
# File 'lib/sportradar/api/baseball/team.rb', line 64
def games
@games_hash.values
end
|
#get_roster ⇒ Object
101
102
103
104
|
# File 'lib/sportradar/api/baseball/team.rb', line 101
def get_roster
data = api.get_data(path_roster).to_h
ingest_roster(data)
end
|
#get_season_stats(year = Date.today.year) ⇒ Object
114
115
116
117
|
# File 'lib/sportradar/api/baseball/team.rb', line 114
def get_season_stats(year = Date.today.year)
data = api.get_data(path_season_stats(year)).to_h
ingest_season_stats(data)
end
|
#handle_names(data) ⇒ Object
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/sportradar/api/baseball/team.rb', line 49
def handle_names(data)
@name = data['name'] if data['name']
if data['name'] && data['market']
@market = data['market']
@full_name = [@market, data['name']].join(' ')
elsif data['name'] && !data.key?('market')
@full_name = data['name']
end
end
|
#ingest_roster(data) ⇒ Object
105
106
107
108
|
# File 'lib/sportradar/api/baseball/team.rb', line 105
def ingest_roster(data)
update(data)
data
end
|
#ingest_season_stats(data) ⇒ Object
118
119
120
|
# File 'lib/sportradar/api/baseball/team.rb', line 118
def ingest_season_stats(data)
parse_season_stats(data)
end
|
#parse_players(data, game) ⇒ Object
80
81
82
|
# File 'lib/sportradar/api/baseball/team.rb', line 80
def parse_players(data, game)
create_data(@players_hash, data, klass: Player, api: api, team: self, game: game)
end
|
#parse_records(data) ⇒ Object
86
87
88
|
# File 'lib/sportradar/api/baseball/team.rb', line 86
def parse_records(data)
@records['overall'] = Record.new(data, type: 'overall')
end
|
#parse_season_stats(data) ⇒ Object
90
91
92
93
94
95
96
|
# File 'lib/sportradar/api/baseball/team.rb', line 90
def parse_season_stats(data)
@team_stats = data.dig('statistics')
update(data)
player_data = data.dig('players')
create_data(@players_hash, player_data, klass: Player, api: api, team: self)
data
end
|
#path_base ⇒ Object
127
128
129
|
# File 'lib/sportradar/api/baseball/team.rb', line 127
def path_base
"teams/#{ id }"
end
|
#path_base_stats(season_year = api.default_year, default_season = api.default_season) ⇒ Object
130
131
132
|
# File 'lib/sportradar/api/baseball/team.rb', line 130
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
133
134
135
|
# File 'lib/sportradar/api/baseball/team.rb', line 133
def path_roster
"#{ path_base }/profile"
end
|
#path_season_stats(year) ⇒ Object
136
137
138
|
# File 'lib/sportradar/api/baseball/team.rb', line 136
def path_season_stats(year)
"#{ path_base_stats(year) }/statistics"
end
|
#players ⇒ Object
Also known as:
roster
71
72
73
74
|
# File 'lib/sportradar/api/baseball/team.rb', line 71
def players
get_roster if @players_hash.empty?
@players_hash.values
end
|
#queue_roster ⇒ Object
109
110
111
112
|
# File 'lib/sportradar/api/baseball/team.rb', line 109
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(year = Date.today.year) ⇒ Object
121
122
123
124
|
# File 'lib/sportradar/api/baseball/team.rb', line 121
def queue_season_stats(year = Date.today.year)
url, , options, timeout = api.get_request_info(path_season_stats(year))
{url: url, headers: , params: options, timeout: timeout, callback: method(:ingest_season_stats)}
end
|
#record(type = 'overall') ⇒ Object
60
61
62
|
# File 'lib/sportradar/api/baseball/team.rb', line 60
def record(type = 'overall')
@records[type]
end
|
#update(data, **opts) ⇒ Object
22
23
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
|
# File 'lib/sportradar/api/baseball/team.rb', line 22
def update(data, **opts)
handle_names(data)
@venue = Venue.new(data['venue']) if data['venue']
@alias = data['abbr'] if data['abbr']
@runs = data['runs'].to_i if data['runs']
parse_records(data) if data['win']
parse_players(data.dig('players'), opts[:game]) if data.dig('players')
if opts[:game]
opts[:game].update_stats(self, data['statistics']) if data['statistics']
end
end
|
#update_player_stats(player, stats, game = nil) ⇒ Object
83
84
85
|
# File 'lib/sportradar/api/baseball/team.rb', line 83
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
|