class Sportradar::Mlb::Models::Pitch
Attributes
attributes[R]
Public Class Methods
from_at_bats(game_id:, at_bats: [])
click to toggle source
# File lib/sportradar/mlb/models/pitch.rb, line 150 def self.from_at_bats(game_id:, at_bats: []) [].tap do |pitches| at_bats.each do |at_bat| at_bat.events.each do |event| if event['type'] == 'pitch' && event['status'] == 'official' pitches << new(attributes: event['pitcher']. merge('game_id' => game_id). merge('at_bat_id' => at_bat.id, 'event_id' => event['id'], 'pitched_at' => event['created_at'], 'pitcher_id' => event['pitcher']['id'], 'pitch_outcome_type' => event['outcome_id'], 'hitter_id' => at_bat.hitter_id, 'hit_type' => event['hit_type'], 'hit_location' => event['hit_location']). merge((event['count'] || {}).transform_keys { |key| key.dup.to_s.prepend('at_bat_') }). merge(event['flags']). merge(at_bat.time_code). merge('pitch_outcome' => PitchOutcome.new(outcome: event['outcome_id']). to_s). except('id')) end end end end end
new(attributes:)
click to toggle source
# File lib/sportradar/mlb/models/pitch.rb, line 5 def initialize(attributes:) @attributes = attributes end
Public Instance Methods
at_bat?()
click to toggle source
# File lib/sportradar/mlb/models/pitch.rb, line 81 def at_bat? attributes['is_ab'] || false end
at_bat_balls()
click to toggle source
# File lib/sportradar/mlb/models/pitch.rb, line 13 def at_bat_balls attributes['at_bat_balls'] || 0 end
at_bat_id()
click to toggle source
# File lib/sportradar/mlb/models/pitch.rb, line 45 def at_bat_id attributes['at_bat_id'] end
at_bat_outs()
click to toggle source
# File lib/sportradar/mlb/models/pitch.rb, line 17 def at_bat_outs attributes['at_bat_outs'] || 0 end
at_bat_over?()
click to toggle source
# File lib/sportradar/mlb/models/pitch.rb, line 85 def at_bat_over? attributes['is_ab_over'] || false end
at_bat_pitch_count()
click to toggle source
# File lib/sportradar/mlb/models/pitch.rb, line 21 def at_bat_pitch_count attributes['at_bat_pitch_count'] || 0 end
at_bat_strikes()
click to toggle source
# File lib/sportradar/mlb/models/pitch.rb, line 25 def at_bat_strikes attributes['at_bat_strikes'] || 0 end
bunt?()
click to toggle source
# File lib/sportradar/mlb/models/pitch.rb, line 89 def bunt? attributes['is_bunt'] || false end
bunt_shown?()
click to toggle source
# File lib/sportradar/mlb/models/pitch.rb, line 93 def bunt_shown? attributes['is_bunt_shown'] || false end
double_play?()
click to toggle source
# File lib/sportradar/mlb/models/pitch.rb, line 97 def double_play? attributes['is_double_play'] || false end
event_id()
click to toggle source
# File lib/sportradar/mlb/models/pitch.rb, line 49 def event_id attributes['event_id'] end
game_id()
click to toggle source
# File lib/sportradar/mlb/models/pitch.rb, line 53 def game_id attributes['game_id'] end
half()
click to toggle source
# File lib/sportradar/mlb/models/pitch.rb, line 129 def half attributes['half'] || '' end
hit?()
click to toggle source
# File lib/sportradar/mlb/models/pitch.rb, line 101 def hit? attributes['is_hit'] || false end
hit_location()
click to toggle source
# File lib/sportradar/mlb/models/pitch.rb, line 73 def hit_location attributes['hit_location'] end
hit_type()
click to toggle source
# File lib/sportradar/mlb/models/pitch.rb, line 69 def hit_type attributes['hit_type'] end
hitter_id()
click to toggle source
# File lib/sportradar/mlb/models/pitch.rb, line 65 def hitter_id attributes['hitter_id'] end
inning()
click to toggle source
# File lib/sportradar/mlb/models/pitch.rb, line 125 def inning attributes['inning'] || 0 end
number()
click to toggle source
# File lib/sportradar/mlb/models/pitch.rb, line 121 def number attributes['number'] || 0 end
on_base?()
click to toggle source
# File lib/sportradar/mlb/models/pitch.rb, line 105 def on_base? attributes['is_on_base'] || false end
passed_ball?()
click to toggle source
# File lib/sportradar/mlb/models/pitch.rb, line 109 def passed_ball? attributes['is_passed_ball'] || false end
pitch_count()
click to toggle source
# File lib/sportradar/mlb/models/pitch.rb, line 29 def pitch_count attributes['pitch_count'] || 0 end
pitch_name()
click to toggle source
# File lib/sportradar/mlb/models/pitch.rb, line 145 def pitch_name PitchType.new(pitch_type: pitch_type). name || '' end
pitch_outcome()
click to toggle source
# File lib/sportradar/mlb/models/pitch.rb, line 137 def pitch_outcome attributes['pitch_outcome'] || '' end
pitch_outcome_type()
click to toggle source
# File lib/sportradar/mlb/models/pitch.rb, line 61 def pitch_outcome_type attributes['pitch_outcome_type'] end
pitch_speed()
click to toggle source
# File lib/sportradar/mlb/models/pitch.rb, line 33 def pitch_speed attributes['pitch_speed'] || 0 end
pitch_type()
click to toggle source
# File lib/sportradar/mlb/models/pitch.rb, line 37 def pitch_type attributes['pitch_type'] || '' end
pitch_zone()
click to toggle source
# File lib/sportradar/mlb/models/pitch.rb, line 41 def pitch_zone attributes['pitch_zone'] || '' end
pitched_at()
click to toggle source
# File lib/sportradar/mlb/models/pitch.rb, line 77 def pitched_at attributes['pitched_at'] end
pitcher_id()
click to toggle source
# File lib/sportradar/mlb/models/pitch.rb, line 57 def pitcher_id attributes['pitcher_id'] end
sequence()
click to toggle source
# File lib/sportradar/mlb/models/pitch.rb, line 133 def sequence attributes['sequence'] || 0 end
to_s()
click to toggle source
# File lib/sportradar/mlb/models/pitch.rb, line 9 def to_s "#{pitch_name} = #{pitch_outcome}" end
triple_play?()
click to toggle source
# File lib/sportradar/mlb/models/pitch.rb, line 113 def triple_play? attributes['is_triple_play'] || false end
wild_pitch?()
click to toggle source
# File lib/sportradar/mlb/models/pitch.rb, line 117 def wild_pitch? attributes['is_wild_pitch'] || false end