class Sportradar::Mlb::Models::AtBat
Attributes
attributes[R]
Public Class Methods
from_innings(game_id:, innings:)
click to toggle source
# File lib/sportradar/mlb/models/at_bat.rb, line 53 def self.from_innings(game_id:, innings:) [].tap do |at_bats| innings.each do |inning| (inning['halfs'] || []).each do |halfs| (halfs['events'] || []).each do |event| if event.has_key?('at_bat') at_bats << new(attributes: (event['at_bat'] || {}). merge('game_id' => game_id). merge('time_code' => { 'number' => inning['number'], 'inning' => inning['sequence'], 'half' => halfs['half'], 'sequence' => inning['sequence'] })) end end end end end end
new(attributes: {})
click to toggle source
# File lib/sportradar/mlb/models/at_bat.rb, line 5 def initialize(attributes: {}) @attributes = attributes end
Public Instance Methods
description()
click to toggle source
# File lib/sportradar/mlb/models/at_bat.rb, line 13 def description attributes['description'] || '' end
events()
click to toggle source
# File lib/sportradar/mlb/models/at_bat.rb, line 17 def events attributes['events'] || [] end
game_id()
click to toggle source
# File lib/sportradar/mlb/models/at_bat.rb, line 21 def game_id attributes['game_id'] end
half()
click to toggle source
# File lib/sportradar/mlb/models/at_bat.rb, line 37 def half time_code['half'] || '' end
hitter_id()
click to toggle source
# File lib/sportradar/mlb/models/at_bat.rb, line 25 def hitter_id attributes['hitter_id'] end
id()
click to toggle source
# File lib/sportradar/mlb/models/at_bat.rb, line 29 def id attributes['id'] end
inning()
click to toggle source
# File lib/sportradar/mlb/models/at_bat.rb, line 41 def inning time_code['inning'] || 0 end
number()
click to toggle source
# File lib/sportradar/mlb/models/at_bat.rb, line 45 def number time_code['number'] || 0 end
sequence()
click to toggle source
# File lib/sportradar/mlb/models/at_bat.rb, line 49 def sequence time_code['sequence'] || 0 end
time_code()
click to toggle source
# File lib/sportradar/mlb/models/at_bat.rb, line 33 def time_code attributes['time_code'] end
to_s()
click to toggle source
# File lib/sportradar/mlb/models/at_bat.rb, line 9 def to_s "#{half} of #{inning}: #{description}" end