Class: Sportradar::Mlb::Models::Pitch
- Inherits:
-
Object
- Object
- Sportradar::Mlb::Models::Pitch
- Defined in:
- lib/sportradar/mlb/models/pitch.rb
Class Method Summary collapse
Instance Method Summary collapse
- #at_bat? ⇒ Boolean
- #at_bat_balls ⇒ Object
- #at_bat_id ⇒ Object
- #at_bat_outs ⇒ Object
- #at_bat_over? ⇒ Boolean
- #at_bat_pitch_count ⇒ Object
- #at_bat_strikes ⇒ Object
- #bunt? ⇒ Boolean
- #bunt_shown? ⇒ Boolean
- #double_play? ⇒ Boolean
- #event_id ⇒ Object
- #game_id ⇒ Object
- #half ⇒ Object
- #hit? ⇒ Boolean
- #hit_location ⇒ Object
- #hit_type ⇒ Object
- #hitter_id ⇒ Object
-
#initialize(attributes:) ⇒ Pitch
constructor
A new instance of Pitch.
- #inning ⇒ Object
- #number ⇒ Object
- #on_base? ⇒ Boolean
- #passed_ball? ⇒ Boolean
- #pitch_count ⇒ Object
- #pitch_name ⇒ Object
- #pitch_outcome ⇒ Object
- #pitch_outcome_type ⇒ Object
- #pitch_speed ⇒ Object
- #pitch_type ⇒ Object
- #pitch_zone ⇒ Object
- #pitched_at ⇒ Object
- #pitcher_id ⇒ Object
- #sequence ⇒ Object
- #to_s ⇒ Object
- #triple_play? ⇒ Boolean
- #wild_pitch? ⇒ Boolean
Constructor Details
#initialize(attributes:) ⇒ Pitch
Returns a new instance of Pitch.
5 6 7 |
# File 'lib/sportradar/mlb/models/pitch.rb', line 5 def initialize(attributes:) @attributes = attributes end |
Class Method Details
.from_at_bats(game_id:, at_bats: []) ⇒ Object
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# 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 |
Instance Method Details
#at_bat? ⇒ Boolean
81 82 83 |
# File 'lib/sportradar/mlb/models/pitch.rb', line 81 def at_bat? attributes['is_ab'] || false end |
#at_bat_balls ⇒ Object
13 14 15 |
# File 'lib/sportradar/mlb/models/pitch.rb', line 13 def at_bat_balls attributes['at_bat_balls'] || 0 end |
#at_bat_id ⇒ Object
45 46 47 |
# File 'lib/sportradar/mlb/models/pitch.rb', line 45 def at_bat_id attributes['at_bat_id'] end |
#at_bat_outs ⇒ Object
17 18 19 |
# File 'lib/sportradar/mlb/models/pitch.rb', line 17 def at_bat_outs attributes['at_bat_outs'] || 0 end |
#at_bat_over? ⇒ Boolean
85 86 87 |
# File 'lib/sportradar/mlb/models/pitch.rb', line 85 def at_bat_over? attributes['is_ab_over'] || false end |
#at_bat_pitch_count ⇒ Object
21 22 23 |
# File 'lib/sportradar/mlb/models/pitch.rb', line 21 def at_bat_pitch_count attributes['at_bat_pitch_count'] || 0 end |
#at_bat_strikes ⇒ Object
25 26 27 |
# File 'lib/sportradar/mlb/models/pitch.rb', line 25 def at_bat_strikes attributes['at_bat_strikes'] || 0 end |
#bunt? ⇒ Boolean
89 90 91 |
# File 'lib/sportradar/mlb/models/pitch.rb', line 89 def bunt? attributes['is_bunt'] || false end |
#bunt_shown? ⇒ Boolean
93 94 95 |
# File 'lib/sportradar/mlb/models/pitch.rb', line 93 def bunt_shown? attributes['is_bunt_shown'] || false end |
#double_play? ⇒ Boolean
97 98 99 |
# File 'lib/sportradar/mlb/models/pitch.rb', line 97 def double_play? attributes['is_double_play'] || false end |
#event_id ⇒ Object
49 50 51 |
# File 'lib/sportradar/mlb/models/pitch.rb', line 49 def event_id attributes['event_id'] end |
#game_id ⇒ Object
53 54 55 |
# File 'lib/sportradar/mlb/models/pitch.rb', line 53 def game_id attributes['game_id'] end |
#half ⇒ Object
129 130 131 |
# File 'lib/sportradar/mlb/models/pitch.rb', line 129 def half attributes['half'] || '' end |
#hit? ⇒ Boolean
101 102 103 |
# File 'lib/sportradar/mlb/models/pitch.rb', line 101 def hit? attributes['is_hit'] || false end |
#hit_location ⇒ Object
73 74 75 |
# File 'lib/sportradar/mlb/models/pitch.rb', line 73 def hit_location attributes['hit_location'] end |
#hit_type ⇒ Object
69 70 71 |
# File 'lib/sportradar/mlb/models/pitch.rb', line 69 def hit_type attributes['hit_type'] end |
#hitter_id ⇒ Object
65 66 67 |
# File 'lib/sportradar/mlb/models/pitch.rb', line 65 def hitter_id attributes['hitter_id'] end |
#inning ⇒ Object
125 126 127 |
# File 'lib/sportradar/mlb/models/pitch.rb', line 125 def inning attributes['inning'] || 0 end |
#number ⇒ Object
121 122 123 |
# File 'lib/sportradar/mlb/models/pitch.rb', line 121 def number attributes['number'] || 0 end |
#on_base? ⇒ Boolean
105 106 107 |
# File 'lib/sportradar/mlb/models/pitch.rb', line 105 def on_base? attributes['is_on_base'] || false end |
#passed_ball? ⇒ Boolean
109 110 111 |
# File 'lib/sportradar/mlb/models/pitch.rb', line 109 def passed_ball? attributes['is_passed_ball'] || false end |
#pitch_count ⇒ Object
29 30 31 |
# File 'lib/sportradar/mlb/models/pitch.rb', line 29 def pitch_count attributes['pitch_count'] || 0 end |
#pitch_name ⇒ Object
145 146 147 148 |
# File 'lib/sportradar/mlb/models/pitch.rb', line 145 def pitch_name PitchType.new(pitch_type: pitch_type). name || '' end |
#pitch_outcome ⇒ Object
137 138 139 |
# File 'lib/sportradar/mlb/models/pitch.rb', line 137 def pitch_outcome attributes['pitch_outcome'] || '' end |
#pitch_outcome_type ⇒ Object
61 62 63 |
# File 'lib/sportradar/mlb/models/pitch.rb', line 61 def pitch_outcome_type attributes['pitch_outcome_type'] end |
#pitch_speed ⇒ Object
33 34 35 |
# File 'lib/sportradar/mlb/models/pitch.rb', line 33 def pitch_speed attributes['pitch_speed'] || 0 end |
#pitch_type ⇒ Object
37 38 39 |
# File 'lib/sportradar/mlb/models/pitch.rb', line 37 def pitch_type attributes['pitch_type'] || '' end |
#pitch_zone ⇒ Object
41 42 43 |
# File 'lib/sportradar/mlb/models/pitch.rb', line 41 def pitch_zone attributes['pitch_zone'] || '' end |
#pitched_at ⇒ Object
77 78 79 |
# File 'lib/sportradar/mlb/models/pitch.rb', line 77 def pitched_at attributes['pitched_at'] end |
#pitcher_id ⇒ Object
57 58 59 |
# File 'lib/sportradar/mlb/models/pitch.rb', line 57 def pitcher_id attributes['pitcher_id'] end |
#sequence ⇒ Object
133 134 135 |
# File 'lib/sportradar/mlb/models/pitch.rb', line 133 def sequence attributes['sequence'] || 0 end |
#to_s ⇒ Object
9 10 11 |
# File 'lib/sportradar/mlb/models/pitch.rb', line 9 def to_s "#{pitch_name} = #{pitch_outcome}" end |
#triple_play? ⇒ Boolean
113 114 115 |
# File 'lib/sportradar/mlb/models/pitch.rb', line 113 def triple_play? attributes['is_triple_play'] || false end |
#wild_pitch? ⇒ Boolean
117 118 119 |
# File 'lib/sportradar/mlb/models/pitch.rb', line 117 def wild_pitch? attributes['is_wild_pitch'] || false end |