Class: Sportradar::Api::Baseball::Game
- Defined in:
- lib/sportradar/api/baseball/game.rb
Constant Summary collapse
- DEFAULT_BASES =
{ '1' => nil, '2' => nil, '3' => nil }
Instance Attribute Summary collapse
-
#attendance ⇒ Object
Returns the value of attribute attendance.
-
#away_id ⇒ Object
Returns the value of attribute away_id.
-
#bases ⇒ Object
readonly
Returns the value of attribute bases.
-
#broadcast ⇒ Object
Returns the value of attribute broadcast.
-
#changes ⇒ Object
Returns the value of attribute changes.
-
#count ⇒ Object
readonly
Returns the value of attribute count.
-
#coverage ⇒ Object
Returns the value of attribute coverage.
-
#duration ⇒ Object
Returns the value of attribute duration.
-
#final ⇒ Object
readonly
Returns the value of attribute final.
-
#half ⇒ Object
readonly
Returns the value of attribute half.
-
#home_id ⇒ Object
Returns the value of attribute home_id.
-
#id ⇒ Object
Returns the value of attribute id.
-
#inning ⇒ Object
readonly
Returns the value of attribute inning.
-
#inning_over ⇒ Object
readonly
Returns the value of attribute inning_over.
-
#lineup ⇒ Object
Returns the value of attribute lineup.
-
#outcome ⇒ Object
readonly
Returns the value of attribute outcome.
-
#outs ⇒ Object
readonly
Returns the value of attribute outs.
-
#pitchers ⇒ Object
readonly
Returns the value of attribute pitchers.
-
#player_stats ⇒ Object
Returns the value of attribute player_stats.
-
#rescheduled ⇒ Object
readonly
Returns the value of attribute rescheduled.
-
#response ⇒ Object
Returns the value of attribute response.
-
#scheduled ⇒ Object
Returns the value of attribute scheduled.
-
#score ⇒ Object
Returns the value of attribute score.
-
#status ⇒ Object
Returns the value of attribute status.
-
#team_stats ⇒ Object
Returns the value of attribute team_stats.
-
#title ⇒ Object
Returns the value of attribute title.
-
#venue ⇒ Object
Returns the value of attribute venue.
Instance Method Summary collapse
- #advance_inning ⇒ Object
- #api ⇒ Object
- #assign_away(team) ⇒ Object
- #assign_home(team) ⇒ Object
- #at_bats ⇒ Object
- #away ⇒ Object
- #box ⇒ Object
- #cancelled? ⇒ Boolean
- #changed?(key) ⇒ Boolean
- #check_newness(key, new_object) ⇒ Object
- #clock ⇒ Object
- #closed? ⇒ Boolean
- #completed? ⇒ Boolean
- #delayed? ⇒ Boolean
- #errors(team_id) ⇒ Object
- #events ⇒ Object
-
#extract_count(data) ⇒ Object
extract from pbp.
- #finished? ⇒ Boolean
- #future? ⇒ Boolean
-
#get_box ⇒ Object
data retrieval.
- #get_pbp ⇒ Object
- #get_summary ⇒ Object
- #half_innings ⇒ Object
- #half_short ⇒ Object
- #half_word ⇒ Object
-
#hits(team_id) ⇒ Object
def runs(team_id) summary_stat(team_id, ‘runs’) end.
- #home ⇒ Object
- #ingest_box(data) ⇒ Object
- #ingest_pbp(data) ⇒ Object
- #ingest_summary(data) ⇒ Object
-
#initialize(data, **opts) ⇒ Game
constructor
A new instance of Game.
- #inning_abbr ⇒ Object
- #inning_short ⇒ Object
- #inning_word ⇒ Object
- #innings ⇒ Object
- #leading_team ⇒ Object
- #leading_team_id ⇒ Object
- #not_updated?(key, object) ⇒ Boolean
- #ordinalize_inning(i) ⇒ Object
- #parse_pitchers(data) ⇒ Object
- #parse_score(data) ⇒ Object
-
#path_base ⇒ Object
url path helpers.
- #path_box ⇒ Object
- #path_pbp ⇒ Object
- #path_summary ⇒ Object
- #pbp ⇒ Object
- #period ⇒ Object
- #pitches ⇒ Object
- #postponed? ⇒ Boolean
- #queue_pbp ⇒ Object
- #queue_summary ⇒ Object
-
#realtime_state(full_word: false) ⇒ Object
status helpers.
-
#remember(key, object) ⇒ Object
tracking updates.
- #runs(team_id) ⇒ Object
- #scoring ⇒ Object
- #set_pbp(data) ⇒ Object
- #sim! ⇒ Object
- #started? ⇒ Boolean
- #stats(team_id) ⇒ Object
- #summary ⇒ Object
- #summary_stat(team_id, stat_name) ⇒ Object
- #team(team_id) ⇒ Object
- #tied? ⇒ Boolean
- #timeouts ⇒ Object
- #unnecessary? ⇒ Boolean
- #update(data, source: nil, **opts) ⇒ Object
-
#update_bases(data) ⇒ Object
def update_from_team(id, data) end.
- #update_player_stats(player, stats) ⇒ Object
- #update_score(score) ⇒ Object
- #update_stats(team, stats) ⇒ Object
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) ⇒ Game
Returns a new instance of Game.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/sportradar/api/baseball/game.rb', line 11 def initialize(data, **opts) @response = data @api = opts[:api] # @season = opts[:season] @updates = {} @changes = {} @score = {} @team_stats = {} @player_stats = {} @scoring_raw = Scoring.new(data, game: self) @lineup = Lineup.new(data, game: self) @teams_hash = {} @innings_hash = {} @home_runs = nil @away_runs = nil @home_id = nil @away_id = nil @outcome = Outcome.new(data, game: self) @count = {} @pitchers = {} @bases = { '1' => nil, '2' => nil, '3' => nil } @id = data['id'] update(data, **opts) end |
Instance Attribute Details
#attendance ⇒ Object
Returns the value of attribute attendance.
5 6 7 |
# File 'lib/sportradar/api/baseball/game.rb', line 5 def attendance @attendance end |
#away_id ⇒ Object
Returns the value of attribute away_id.
5 6 7 |
# File 'lib/sportradar/api/baseball/game.rb', line 5 def away_id @away_id end |
#bases ⇒ Object (readonly)
Returns the value of attribute bases.
7 8 9 |
# File 'lib/sportradar/api/baseball/game.rb', line 7 def bases @bases end |
#broadcast ⇒ Object
Returns the value of attribute broadcast.
5 6 7 |
# File 'lib/sportradar/api/baseball/game.rb', line 5 def broadcast @broadcast end |
#changes ⇒ Object
Returns the value of attribute changes.
5 6 7 |
# File 'lib/sportradar/api/baseball/game.rb', line 5 def changes @changes end |
#count ⇒ Object (readonly)
Returns the value of attribute count.
8 9 10 |
# File 'lib/sportradar/api/baseball/game.rb', line 8 def count @count end |
#coverage ⇒ Object
Returns the value of attribute coverage.
5 6 7 |
# File 'lib/sportradar/api/baseball/game.rb', line 5 def coverage @coverage end |
#duration ⇒ Object
Returns the value of attribute duration.
5 6 7 |
# File 'lib/sportradar/api/baseball/game.rb', line 5 def duration @duration end |
#final ⇒ Object (readonly)
Returns the value of attribute final.
7 8 9 |
# File 'lib/sportradar/api/baseball/game.rb', line 7 def final @final end |
#half ⇒ Object (readonly)
Returns the value of attribute half.
7 8 9 |
# File 'lib/sportradar/api/baseball/game.rb', line 7 def half @half end |
#home_id ⇒ Object
Returns the value of attribute home_id.
5 6 7 |
# File 'lib/sportradar/api/baseball/game.rb', line 5 def home_id @home_id end |
#id ⇒ Object
Returns the value of attribute id.
5 6 7 |
# File 'lib/sportradar/api/baseball/game.rb', line 5 def id @id end |
#inning ⇒ Object (readonly)
Returns the value of attribute inning.
7 8 9 |
# File 'lib/sportradar/api/baseball/game.rb', line 7 def inning @inning end |
#inning_over ⇒ Object (readonly)
Returns the value of attribute inning_over.
7 8 9 |
# File 'lib/sportradar/api/baseball/game.rb', line 7 def inning_over @inning_over end |
#lineup ⇒ Object
Returns the value of attribute lineup.
5 6 7 |
# File 'lib/sportradar/api/baseball/game.rb', line 5 def lineup @lineup end |
#outcome ⇒ Object (readonly)
Returns the value of attribute outcome.
8 9 10 |
# File 'lib/sportradar/api/baseball/game.rb', line 8 def outcome @outcome end |
#outs ⇒ Object (readonly)
Returns the value of attribute outs.
7 8 9 |
# File 'lib/sportradar/api/baseball/game.rb', line 7 def outs @outs end |
#pitchers ⇒ Object (readonly)
Returns the value of attribute pitchers.
7 8 9 |
# File 'lib/sportradar/api/baseball/game.rb', line 7 def pitchers @pitchers end |
#player_stats ⇒ Object
Returns the value of attribute player_stats.
5 6 7 |
# File 'lib/sportradar/api/baseball/game.rb', line 5 def player_stats @player_stats end |
#rescheduled ⇒ Object (readonly)
Returns the value of attribute rescheduled.
7 8 9 |
# File 'lib/sportradar/api/baseball/game.rb', line 7 def rescheduled @rescheduled end |
#response ⇒ Object
Returns the value of attribute response.
5 6 7 |
# File 'lib/sportradar/api/baseball/game.rb', line 5 def response @response end |
#scheduled ⇒ Object
Returns the value of attribute scheduled.
5 6 7 |
# File 'lib/sportradar/api/baseball/game.rb', line 5 def scheduled @scheduled end |
#score ⇒ Object
Returns the value of attribute score.
5 6 7 |
# File 'lib/sportradar/api/baseball/game.rb', line 5 def score @score end |
#status ⇒ Object
Returns the value of attribute status.
5 6 7 |
# File 'lib/sportradar/api/baseball/game.rb', line 5 def status @status end |
#team_stats ⇒ Object
Returns the value of attribute team_stats.
5 6 7 |
# File 'lib/sportradar/api/baseball/game.rb', line 5 def team_stats @team_stats end |
#title ⇒ Object
Returns the value of attribute title.
5 6 7 |
# File 'lib/sportradar/api/baseball/game.rb', line 5 def title @title end |
#venue ⇒ Object
Returns the value of attribute venue.
5 6 7 |
# File 'lib/sportradar/api/baseball/game.rb', line 5 def venue @venue end |
Instance Method Details
#advance_inning ⇒ Object
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/sportradar/api/baseball/game.rb', line 174 def advance_inning @inning_over = false return unless count['outs'] == 3 if count['inning'] >= 9 if count['inning_half'] == 'T' && leading_team_id == home.id return elsif count['inning_half'] == 'B' && !tied? return end end @inning_over = true @bases = DEFAULT_BASES.dup half, inn = if count['inning_half'] == 'B' ['E', count['inning']] elsif count['inning_half'] == 'T' ['M', count['inning']] else [nil, 1] end @count = { 'balls' => 0, 'strikes' => 0, 'outs' => 0, 'inning' => inn, 'inning_half' => half, } end |
#api ⇒ Object
480 481 482 |
# File 'lib/sportradar/api/baseball/game.rb', line 480 def api @api ||= Sportradar::Api::Baseball::Mlb::Api.new end |
#assign_away(team) ⇒ Object
239 240 241 242 |
# File 'lib/sportradar/api/baseball/game.rb', line 239 def assign_away(team) @away_id = team.id @teams_hash[team.id] = team end |
#assign_home(team) ⇒ Object
234 235 236 237 |
# File 'lib/sportradar/api/baseball/game.rb', line 234 def assign_home(team) @home_id = team.id @teams_hash[team.id] = team end |
#at_bats ⇒ Object
259 260 261 |
# File 'lib/sportradar/api/baseball/game.rb', line 259 def at_bats events.map(&:at_bat).compact end |
#away ⇒ Object
217 218 219 |
# File 'lib/sportradar/api/baseball/game.rb', line 217 def away @teams_hash[@away_id] || @away end |
#box ⇒ Object
244 245 246 |
# File 'lib/sportradar/api/baseball/game.rb', line 244 def box @box ||= get_box end |
#cancelled? ⇒ Boolean
370 371 372 |
# File 'lib/sportradar/api/baseball/game.rb', line 370 def cancelled? ['unnecessary', 'postponed'].include? status end |
#changed?(key) ⇒ Boolean
287 288 289 |
# File 'lib/sportradar/api/baseball/game.rb', line 287 def changed?(key) @changes[key] end |
#check_newness(key, new_object) ⇒ Object
291 292 293 294 |
# File 'lib/sportradar/api/baseball/game.rb', line 291 def check_newness(key, new_object) @changes[key] = !not_updated?(key, new_object) remember(key, new_object) end |
#clock ⇒ Object
358 359 360 |
# File 'lib/sportradar/api/baseball/game.rb', line 358 def clock half_short end |
#closed? ⇒ Boolean
394 395 396 |
# File 'lib/sportradar/api/baseball/game.rb', line 394 def closed? 'closed' == status end |
#completed? ⇒ Boolean
390 391 392 |
# File 'lib/sportradar/api/baseball/game.rb', line 390 def completed? 'complete' == status end |
#delayed? ⇒ Boolean
374 375 376 |
# File 'lib/sportradar/api/baseball/game.rb', line 374 def delayed? ['wdelay', 'delayed'].include? status end |
#errors(team_id) ⇒ Object
59 60 61 |
# File 'lib/sportradar/api/baseball/game.rb', line 59 def errors(team_id) @scoring_raw.errors(team_id) end |
#events ⇒ Object
255 256 257 |
# File 'lib/sportradar/api/baseball/game.rb', line 255 def events innings.flat_map(&:events) end |
#extract_count(data) ⇒ Object
extract from pbp
202 203 204 205 206 207 208 209 210 211 |
# File 'lib/sportradar/api/baseball/game.rb', line 202 def extract_count(data) # extract from pbp recent_pitches = pitches.last(10) last_pitch = recent_pitches.reverse_each.detect(&:count) return unless last_pitch update_bases(last_pitch) @count.merge!(last_pitch.count) hi = last_pitch.at_bat.event.half_inning @count.merge!('inning' => hi.number.to_i, 'inning_half' => hi.half) advance_inning end |
#finished? ⇒ Boolean
386 387 388 |
# File 'lib/sportradar/api/baseball/game.rb', line 386 def finished? ['complete', 'closed'].include? status end |
#future? ⇒ Boolean
378 379 380 |
# File 'lib/sportradar/api/baseball/game.rb', line 378 def future? ['scheduled', 'delayed', 'created', 'time-tbd'].include? status end |
#get_box ⇒ Object
data retrieval
417 418 419 420 |
# File 'lib/sportradar/api/baseball/game.rb', line 417 def get_box data = api.get_data(path_box) ingest_box(data) end |
#get_pbp ⇒ Object
434 435 436 437 |
# File 'lib/sportradar/api/baseball/game.rb', line 434 def get_pbp data = api.get_data(path_pbp); ingest_pbp(data) end |
#get_summary ⇒ Object
456 457 458 459 |
# File 'lib/sportradar/api/baseball/game.rb', line 456 def get_summary data = api.get_data(path_summary) ingest_summary(data) end |
#half_innings ⇒ Object
274 275 276 |
# File 'lib/sportradar/api/baseball/game.rb', line 274 def half_innings innings.flat_map(&:half_innings) end |
#half_short ⇒ Object
349 350 351 352 353 354 355 356 |
# File 'lib/sportradar/api/baseball/game.rb', line 349 def half_short { 'B' => 'Bot', 'T' => 'Top', 'M' => 'Mid', 'E' => 'End', }.freeze[self.count['inning_half']] end |
#half_word ⇒ Object
340 341 342 343 344 345 346 347 |
# File 'lib/sportradar/api/baseball/game.rb', line 340 def half_word { 'B' => 'Bottom', 'T' => 'Top', 'M' => 'Middle', 'E' => 'End', }.freeze[self.count['inning_half']] end |
#hits(team_id) ⇒ Object
def runs(team_id)
summary_stat(team_id, 'runs')
end
56 57 58 |
# File 'lib/sportradar/api/baseball/game.rb', line 56 def hits(team_id) @scoring_raw.hits(team_id) end |
#home ⇒ Object
213 214 215 |
# File 'lib/sportradar/api/baseball/game.rb', line 213 def home @teams_hash[@home_id] || @home end |
#ingest_box(data) ⇒ Object
422 423 424 425 426 427 |
# File 'lib/sportradar/api/baseball/game.rb', line 422 def ingest_box(data) data = data['game'] update(data, source: :box) check_newness(:box, @clock) data end |
#ingest_pbp(data) ⇒ Object
439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 |
# File 'lib/sportradar/api/baseball/game.rb', line 439 def ingest_pbp(data) data = data['game'] update(data, source: :pbp) innings = data['innings'].each { |inning| inning['id'] = "#{data['id']}-#{inning['number']}" } create_data(@innings_hash, innings, klass: Inning, api: api, game: self) if data['innings'] extract_count(data) lineup.update(data, source: :pbp) # update lineups check_newness(:pitches, pitches.last&.id) check_newness(:events, events.last&.description) check_newness(:score, @score) @pbp = @innings_hash.values data # rescue => e # binding.pry end |
#ingest_summary(data) ⇒ Object
466 467 468 469 470 471 472 473 |
# File 'lib/sportradar/api/baseball/game.rb', line 466 def ingest_summary(data) data = data['game'] update(data, source: :summary) @inning = data.delete('inning').to_i check_newness(:box, @clock) check_newness(:score, @score) data end |
#inning_abbr ⇒ Object
312 313 314 315 316 317 318 |
# File 'lib/sportradar/api/baseball/game.rb', line 312 def inning_abbr if !count.empty? inning_half = self.count['inning_half'] inning = self.count['inning'] "#{inning_half || 'T'}#{(inning || 1)}" end end |
#inning_short ⇒ Object
320 321 322 323 324 325 326 |
# File 'lib/sportradar/api/baseball/game.rb', line 320 def inning_short if !count.empty? inning_half = self.count['inning_half'] inning = self.count['inning'] "#{half_short} #{ordinalize_inning(inning || 1)}" # TODO remove AS dependency end end |
#inning_word ⇒ Object
328 329 330 331 332 333 334 |
# File 'lib/sportradar/api/baseball/game.rb', line 328 def inning_word if !count.empty? inning_half = self.count['inning_half'] inning = self.count['inning'] "#{half_word} #{ordinalize_inning(inning || 1)}" end end |
#innings ⇒ Object
271 272 273 |
# File 'lib/sportradar/api/baseball/game.rb', line 271 def innings @innings_hash.values end |
#leading_team ⇒ Object
226 227 228 |
# File 'lib/sportradar/api/baseball/game.rb', line 226 def leading_team @teams_hash[leading_team_id] || (@away_id == leading_team_id && away) || (@home_id == leading_team_id && home) end |
#leading_team_id ⇒ Object
221 222 223 224 |
# File 'lib/sportradar/api/baseball/game.rb', line 221 def leading_team_id return nil if tied? score.max_by(&:last).first end |
#not_updated?(key, object) ⇒ Boolean
283 284 285 |
# File 'lib/sportradar/api/baseball/game.rb', line 283 def not_updated?(key, object) @updates[key] == object end |
#ordinalize_inning(i) ⇒ Object
336 337 338 |
# File 'lib/sportradar/api/baseball/game.rb', line 336 def ordinalize_inning(i) Sportradar.ordinalize_period(i) end |
#parse_pitchers(data) ⇒ Object
98 99 100 101 102 103 104 105 106 107 |
# File 'lib/sportradar/api/baseball/game.rb', line 98 def parse_pitchers(data) pitchers = { 'starting' => { home_id => data.dig('home', 'starting_pitcher'), away_id => data.dig('away', 'starting_pitcher')}, 'probable' => { home_id => data.dig('home', 'probable_pitcher'), away_id => data.dig('away', 'probable_pitcher')}, 'current' => { home_id => data.dig('home', 'current_pitcher'), away_id => data.dig('away', 'current_pitcher')}, } @pitchers.merge!(pitchers) do |key, current_val, merge_val| current_val.merge(merge_val) { |k, cur, mer| (mer || cur) } end end |
#parse_score(data) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/sportradar/api/baseball/game.rb', line 85 def parse_score(data) home_id = data.dig('home', 'id') away_id = data.dig('away', 'id') rhe = { 'runs' => { home_id => data.dig('home', 'runs'), away_id => data.dig('away', 'runs')}, 'hits' => { home_id => data.dig('home', 'hits'), away_id => data.dig('away', 'hits')}, 'errors' => { home_id => data.dig('home', 'errors'), away_id => data.dig('away', 'errors')}, } @scoring_raw.update(rhe, source: :rhe) update_score(home_id => data.dig('home', 'runs')) update_score(away_id => data.dig('away', 'runs')) end |
#path_base ⇒ Object
url path helpers
399 400 401 |
# File 'lib/sportradar/api/baseball/game.rb', line 399 def path_base "games/#{ id }" end |
#path_box ⇒ Object
403 404 405 |
# File 'lib/sportradar/api/baseball/game.rb', line 403 def path_box "#{ path_base }/boxscore" end |
#path_pbp ⇒ Object
407 408 409 |
# File 'lib/sportradar/api/baseball/game.rb', line 407 def path_pbp "#{ path_base }/pbp" end |
#path_summary ⇒ Object
411 412 413 |
# File 'lib/sportradar/api/baseball/game.rb', line 411 def path_summary "#{ path_base }/summary" end |
#pbp ⇒ Object
248 249 250 251 252 253 |
# File 'lib/sportradar/api/baseball/game.rb', line 248 def pbp if !future? && innings.empty? get_pbp end @pbp ||= innings end |
#period ⇒ Object
46 47 48 |
# File 'lib/sportradar/api/baseball/game.rb', line 46 def period @innings end |
#pitches ⇒ Object
263 264 265 |
# File 'lib/sportradar/api/baseball/game.rb', line 263 def pitches at_bats.flat_map(&:pitches) end |
#postponed? ⇒ Boolean
362 363 364 |
# File 'lib/sportradar/api/baseball/game.rb', line 362 def postponed? 'postponed' == status end |
#queue_pbp ⇒ Object
429 430 431 432 |
# File 'lib/sportradar/api/baseball/game.rb', line 429 def queue_pbp url, headers, , timeout = api.get_request_info(path_pbp) {url: url, headers: headers, params: , timeout: timeout, callback: method(:ingest_pbp)} end |
#queue_summary ⇒ Object
461 462 463 464 |
# File 'lib/sportradar/api/baseball/game.rb', line 461 def queue_summary url, headers, , timeout = api.get_request_info(path_summary) {url: url, headers: headers, params: , timeout: timeout, callback: method(:ingest_summary)} end |
#realtime_state(full_word: false) ⇒ Object
status helpers
298 299 300 301 302 303 304 305 306 307 308 309 310 |
# File 'lib/sportradar/api/baseball/game.rb', line 298 def realtime_state(full_word: false) if future? 'Scheduled' elsif delayed? 'Delayed' elsif finished? 'Final' elsif postponed? 'Postponed' else full_word ? inning_word : inning_short end end |
#remember(key, object) ⇒ Object
tracking updates
279 280 281 |
# File 'lib/sportradar/api/baseball/game.rb', line 279 def remember(key, object) @updates[key] = object&.dup end |
#runs(team_id) ⇒ Object
62 63 64 |
# File 'lib/sportradar/api/baseball/game.rb', line 62 def runs(team_id) team_id.is_a?(Symbol) ? @score[@team_ids[team_id]] : @score[team_id] end |
#scoring ⇒ Object
72 73 74 |
# File 'lib/sportradar/api/baseball/game.rb', line 72 def scoring @scoring_raw.scores end |
#set_pbp(data) ⇒ Object
475 476 477 478 |
# File 'lib/sportradar/api/baseball/game.rb', line 475 def set_pbp(data) create_data(@innings_hash, data, klass: inning_class, api: api, game: self) @innings_hash end |
#sim! ⇒ Object
484 485 486 487 |
# File 'lib/sportradar/api/baseball/game.rb', line 484 def sim! @api = api.sim! self end |
#started? ⇒ Boolean
382 383 384 |
# File 'lib/sportradar/api/baseball/game.rb', line 382 def started? ['inprogress', 'wdelay', 'delayed'].include? status end |
#stats(team_id) ⇒ Object
68 69 70 |
# File 'lib/sportradar/api/baseball/game.rb', line 68 def stats(team_id) team_id.is_a?(Symbol) ? @team_stats[@team_ids[team_id]].to_i : @team_stats[team_id].to_i end |
#summary ⇒ Object
267 268 269 |
# File 'lib/sportradar/api/baseball/game.rb', line 267 def summary @summary ||= get_summary end |
#summary_stat(team_id, stat_name) ⇒ Object
65 66 67 |
# File 'lib/sportradar/api/baseball/game.rb', line 65 def summary_stat(team_id, stat_name) scoring.dig(team_id, stat_name) end |
#team(team_id) ⇒ Object
230 231 232 |
# File 'lib/sportradar/api/baseball/game.rb', line 230 def team(team_id) @teams_hash[team_id] end |
#tied? ⇒ Boolean
50 51 52 |
# File 'lib/sportradar/api/baseball/game.rb', line 50 def tied? @score[away_id].to_i == @score[home_id].to_i end |
#timeouts ⇒ Object
42 43 44 |
# File 'lib/sportradar/api/baseball/game.rb', line 42 def timeouts {} end |
#unnecessary? ⇒ Boolean
366 367 368 |
# File 'lib/sportradar/api/baseball/game.rb', line 366 def unnecessary? 'unnecessary' == status end |
#update(data, source: nil, **opts) ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/sportradar/api/baseball/game.rb', line 109 def update(data, source: nil, **opts) @response.merge!(data) # via pbp @status = data['status'] if data['status'] @coverage = data['coverage'] if data['coverage'] @day_night = data['day_night'] if data['day_night'] @game_number = data['game_number'] if data['game_number'] @home_id = data['home_team'] || data.dig('home', 'id') if data['home_team'] || data.dig('home', 'id') @away_id = data['away_team'] || data.dig('away', 'id') if data['away_team'] || data.dig('away', 'id') # @home_runs = data['home_runs'].to_i if data['home_runs'] # @away_runs = data['away_runs'].to_i if data['away_runs'] @scheduled = Time.parse(data["scheduled"]) if data["scheduled"] @venue = Venue.new(data['venue']) if data['venue'] @broadcast = Broadcast.new(data['broadcast']) if !data['broadcast'].to_h.empty? @home = Team.new(data['home'] || data.dig('scoring', 'home'), api: api, game: self) if data['home'] || data.dig('scoring', 'home') @away = Team.new(data['away'] || data.dig('scoring', 'away'), api: api, game: self) if data['away'] || data.dig('scoring', 'away') @title = data['title'] || @title || (home && away && "#{home.full_name} vs #{away.full_name}") @duration = data['duration'] if data['duration'] @attendance = data['attendance'] if data['attendance'] @final = data['final'] if data['final'] @rescheduled = data['rescheduled'] if data['rescheduled'] @team_ids = { home: @home_id, away: @away_id} update_bases(data) parse_pitchers(data) if data['home'] && data['away'] lineup.update(data, source: source) unless source == :pbp if data['scoring'] parse_score(data['scoring']) elsif data.dig('home', 'hits') parse_score(data) end @scoring_raw.update(data, source: source) if data['outcome'] @outcome.update(data, source: nil) @count.merge!(@outcome.count || {}) end create_data(@teams_hash, data['team'], klass: Team, api: api, game: self) if data['team'] end |
#update_bases(data) ⇒ Object
def update_from_team(id, data) end
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/sportradar/api/baseball/game.rb', line 156 def update_bases(data) if data.is_a?(Sportradar::Api::Baseball::Error) puts data.inspect return end @bases = if data.respond_to?(:runners) hash = Array(data.runners).map { |runner| [runner.ending_base.to_s, runner.id] if !runner.out }.compact.to_h DEFAULT_BASES.merge(hash) elsif (runners = data.dig('outcome', 'runners')) hash = runners.map { |runner| [runner['ending_base'].to_s, runner['id']] if !runner['out'] }.compact.to_h DEFAULT_BASES.merge(hash) else # probably new inning, no runners DEFAULT_BASES.dup end rescue => e puts data.inspect raise e end |
#update_player_stats(player, stats) ⇒ Object
81 82 83 |
# File 'lib/sportradar/api/baseball/game.rb', line 81 def update_player_stats(player, stats) @player_stats.merge!(player.id => stats.merge!(player: player)) end |
#update_score(score) ⇒ Object
75 76 77 |
# File 'lib/sportradar/api/baseball/game.rb', line 75 def update_score(score) @score.merge!(score) end |
#update_stats(team, stats) ⇒ Object
78 79 80 |
# File 'lib/sportradar/api/baseball/game.rb', line 78 def update_stats(team, stats) @team_stats.merge!(team.id => stats.merge!(team: team)) end |