Class: Sportradar::Api::Baseball::Pitch
- Defined in:
- lib/sportradar/api/baseball/pitch.rb
Instance Attribute Summary collapse
-
#at_bat ⇒ Object
Returns the value of attribute at_bat.
-
#atbat_pitch_count ⇒ Object
Returns the value of attribute atbat_pitch_count.
-
#balls ⇒ Object
Returns the value of attribute balls.
-
#count ⇒ Object
Returns the value of attribute count.
-
#errors ⇒ Object
Returns the value of attribute errors.
-
#fielders ⇒ Object
Returns the value of attribute fielders.
-
#hit_type ⇒ Object
Returns the value of attribute hit_type.
-
#id ⇒ Object
Returns the value of attribute id.
-
#is_ab_over ⇒ Object
Returns the value of attribute is_ab_over.
-
#is_hit ⇒ Object
Returns the value of attribute is_hit.
-
#outcome ⇒ Object
Returns the value of attribute outcome.
-
#outcome_id ⇒ Object
Returns the value of attribute outcome_id.
-
#outs ⇒ Object
Returns the value of attribute outs.
-
#pitch_type_name ⇒ Object
Returns the value of attribute pitch_type_name.
-
#response ⇒ Object
Returns the value of attribute response.
-
#runners ⇒ Object
Returns the value of attribute runners.
-
#speed ⇒ Object
Returns the value of attribute speed.
-
#status ⇒ Object
Returns the value of attribute status.
-
#strikes ⇒ Object
Returns the value of attribute strikes.
-
#total_pitch_count ⇒ Object
Returns the value of attribute total_pitch_count.
-
#warming_up ⇒ Object
Returns the value of attribute warming_up.
-
#x ⇒ Object
Returns the value of attribute x.
-
#y ⇒ Object
Returns the value of attribute y.
-
#zone ⇒ Object
Returns the value of attribute zone.
Class Method Summary collapse
- .pitch_outcome(code) ⇒ Object
- .pitch_outcomes ⇒ Object
- .pitch_type(code) ⇒ Object
- .pitch_types ⇒ Object
Instance Method Summary collapse
- #==(other) ⇒ Object
- #ball? ⇒ Boolean
- #foul? ⇒ Boolean
- #hit_ends_ab? ⇒ Boolean
- #homerun? ⇒ Boolean
-
#initialize(data, **opts) ⇒ Pitch
constructor
A new instance of Pitch.
- #parse_count(data) ⇒ Object
- #parse_errors(data) ⇒ Object
- #parse_fielders(data) ⇒ Object
- #parse_flags(data) ⇒ Object
- #parse_hit(data) ⇒ Object
- #parse_pitcher(data) ⇒ Object
- #parse_runners(data) ⇒ Object
- #parse_steal(data) ⇒ Object
- #parse_warming_up(data) ⇒ Object
- #pitches ⇒ Object
- #strike? ⇒ Boolean
- #update(data, **opts) ⇒ Object
- #updated ⇒ 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) ⇒ Pitch
Returns a new instance of Pitch.
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/sportradar/api/baseball/pitch.rb', line 7 def initialize(data, **opts) @response = data @api = opts[:api] @at_bat = opts[:at_bat] # @half_inning = opts[:half_inning] @id = data["id"] update(data) end |
Instance Attribute Details
#at_bat ⇒ Object
Returns the value of attribute at_bat.
5 6 7 |
# File 'lib/sportradar/api/baseball/pitch.rb', line 5 def at_bat @at_bat end |
#atbat_pitch_count ⇒ Object
Returns the value of attribute atbat_pitch_count.
5 6 7 |
# File 'lib/sportradar/api/baseball/pitch.rb', line 5 def atbat_pitch_count @atbat_pitch_count end |
#balls ⇒ Object
Returns the value of attribute balls.
5 6 7 |
# File 'lib/sportradar/api/baseball/pitch.rb', line 5 def balls @balls end |
#count ⇒ Object
Returns the value of attribute count.
5 6 7 |
# File 'lib/sportradar/api/baseball/pitch.rb', line 5 def count @count end |
#errors ⇒ Object
Returns the value of attribute errors.
5 6 7 |
# File 'lib/sportradar/api/baseball/pitch.rb', line 5 def errors @errors end |
#fielders ⇒ Object
Returns the value of attribute fielders.
5 6 7 |
# File 'lib/sportradar/api/baseball/pitch.rb', line 5 def fielders @fielders end |
#hit_type ⇒ Object
Returns the value of attribute hit_type.
5 6 7 |
# File 'lib/sportradar/api/baseball/pitch.rb', line 5 def hit_type @hit_type end |
#id ⇒ Object
Returns the value of attribute id.
5 6 7 |
# File 'lib/sportradar/api/baseball/pitch.rb', line 5 def id @id end |
#is_ab_over ⇒ Object
Returns the value of attribute is_ab_over.
5 6 7 |
# File 'lib/sportradar/api/baseball/pitch.rb', line 5 def is_ab_over @is_ab_over end |
#is_hit ⇒ Object
Returns the value of attribute is_hit.
5 6 7 |
# File 'lib/sportradar/api/baseball/pitch.rb', line 5 def is_hit @is_hit end |
#outcome ⇒ Object
Returns the value of attribute outcome.
5 6 7 |
# File 'lib/sportradar/api/baseball/pitch.rb', line 5 def outcome @outcome end |
#outcome_id ⇒ Object
Returns the value of attribute outcome_id.
5 6 7 |
# File 'lib/sportradar/api/baseball/pitch.rb', line 5 def outcome_id @outcome_id end |
#outs ⇒ Object
Returns the value of attribute outs.
5 6 7 |
# File 'lib/sportradar/api/baseball/pitch.rb', line 5 def outs @outs end |
#pitch_type_name ⇒ Object
Returns the value of attribute pitch_type_name.
5 6 7 |
# File 'lib/sportradar/api/baseball/pitch.rb', line 5 def pitch_type_name @pitch_type_name end |
#response ⇒ Object
Returns the value of attribute response.
5 6 7 |
# File 'lib/sportradar/api/baseball/pitch.rb', line 5 def response @response end |
#runners ⇒ Object
Returns the value of attribute runners.
5 6 7 |
# File 'lib/sportradar/api/baseball/pitch.rb', line 5 def runners @runners end |
#speed ⇒ Object
Returns the value of attribute speed.
5 6 7 |
# File 'lib/sportradar/api/baseball/pitch.rb', line 5 def speed @speed end |
#status ⇒ Object
Returns the value of attribute status.
5 6 7 |
# File 'lib/sportradar/api/baseball/pitch.rb', line 5 def status @status end |
#strikes ⇒ Object
Returns the value of attribute strikes.
5 6 7 |
# File 'lib/sportradar/api/baseball/pitch.rb', line 5 def strikes @strikes end |
#total_pitch_count ⇒ Object
Returns the value of attribute total_pitch_count.
5 6 7 |
# File 'lib/sportradar/api/baseball/pitch.rb', line 5 def total_pitch_count @total_pitch_count end |
#warming_up ⇒ Object
Returns the value of attribute warming_up.
5 6 7 |
# File 'lib/sportradar/api/baseball/pitch.rb', line 5 def warming_up @warming_up end |
#x ⇒ Object
Returns the value of attribute x.
5 6 7 |
# File 'lib/sportradar/api/baseball/pitch.rb', line 5 def x @x end |
#y ⇒ Object
Returns the value of attribute y.
5 6 7 |
# File 'lib/sportradar/api/baseball/pitch.rb', line 5 def y @y end |
#zone ⇒ Object
Returns the value of attribute zone.
5 6 7 |
# File 'lib/sportradar/api/baseball/pitch.rb', line 5 def zone @zone end |
Class Method Details
.pitch_outcome(code) ⇒ Object
157 158 159 |
# File 'lib/sportradar/api/baseball/pitch.rb', line 157 def self.pitch_outcome(code) pitch_outcomes[code] end |
.pitch_outcomes ⇒ Object
160 161 162 163 164 165 166 167 168 169 170 171 172 173 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 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 |
# File 'lib/sportradar/api/baseball/pitch.rb', line 160 def self.pitch_outcomes @pitch_outcomes ||= { 'aBK' => 'Balk', 'aCI' => 'Catcher Interference', 'aD' => 'Double', 'aDAD3' => 'Double - Adv 3rd', 'aDAD4' => 'Double - Adv Home', 'aFCAD2' => 'Fielders Choice - Adv 2nd', 'aFCAD3' => 'Fielders Choice - Adv 3rd', 'aFCAD4' => 'Fielders Choice - Adv Home', 'aHBP' => 'Hit By Pitch', 'aHR' => 'Homerun', 'aIBB' => 'Intentional Walk', 'aKLAD1' => 'Strike Looking - Adv 1st', 'aKLAD2' => 'Strike Looking - Adv 2nd', 'aKLAD3' => 'Strike Looking - Adv 3rd', 'aKLAD4' => 'Strike Looking - Adv Home', 'aKSAD1' => 'Strike Swinging - Adv 1st', 'aKSAD2' => 'Strike Swinging - Adv 2nd', 'aKSAD3' => 'Strike Swinging - Adv 3rd', 'aKSAD4' => 'Strike Swinging - Adv Home', 'aROE' => 'Reached On Error', 'aROEAD2' => 'Reached On Error - Adv 2nd', 'aROEAD3' => 'Reached On Error - Adv 3rd', 'aROEAD4' => 'Reached On Error - Adv Home', 'aS' => 'Single', 'aSAD2' => 'Single - Adv 2nd', 'aSAD3' => 'Single - Adv 3rd', 'aSAD4' => 'Single - Adv Home', 'aSBAD1' => 'Sacrifice Bunt - Adv 1st', 'aSBAD2' => 'Sacrifice Bunt - Adv 2nd', 'aSBAD3' => 'Sacrifice Bunt - Adv 3rd', 'aSBAD4' => 'Sacrifice Bunt - Adv Home', 'aSFAD1' => 'Sacrifice Fly - Adv 1st', 'aSFAD2' => 'Sacrifice Fly - Adv 2nd', 'aSFAD3' => 'Sacrifice Fly - Adv 3rd', 'aSFAD4' => 'Sacrifice Fly - Adv Home', 'aT' => 'Triple', 'aTAD4' => 'Triple - Adv Home', 'bAB' => 'Enforced Ball', 'bB' => 'Ball', 'bDB' => 'Dirt Ball', 'bIB' => 'Intentional Ball', 'bPO' => 'Pitchout', 'kF' => 'Foul Ball', 'kFT' => 'Foul Tip', 'kKL' => 'Strike Looking', 'kKS' => 'Strike Swinging', 'oBI' => 'Hitter Interference', 'oDT3' => 'Double - Out at 3rd', 'oDT4' => 'Double - Out at Home', 'oFC' => 'Fielders Choice', 'oFCT2' => 'Fielders Choice - Out at 2nd', 'oFCT3' => 'Fielders Choice - Out at 3rd', 'oFCT4' => 'Fielders Choice - Out at Home', 'oFO' => 'Fly Out', 'oGO' => 'Ground Out', 'oKLT1' => 'Strike Looking - Out at 1st', 'oKLT2' => 'Strike Looking - Out at 2nd', 'oKLT3' => 'Strike Looking - Out at 3rd', 'oKLT4' => 'Strike Looking - Out at Home', 'oKST1' => 'Strike Swinging - Out at 1st', 'oKST2' => 'Strike Swinging - Out at 2nd', 'oKST3' => 'Strike Swinging - Out at 3rd', 'oKST4' => 'Strike Swinging - Out at Home', 'oLO' => 'Line Out', 'oOBB' => 'Out of Batters Box', 'oOP' => 'Out on Appeal', 'oPO' => 'Pop Out', 'oROET2' => 'Reached On Error - Out at 2nd', 'oROET3' => 'Reached On Error - Out at 3rd', 'oROET4' => 'Reached On Error - Out at Home', 'oSB' => 'Sacrifice Bunt', 'oSBT2' => 'Sacrifice Bunt - Out at 2nd', 'oSBT3' => 'Sacrifice Bunt - Out at 3rd', 'oSBT4' => 'Sacrifice Bunt - Out at Home', 'oSF' => 'Sacrifice Fly', 'oSFT2' => 'Sacrifice Fly - Out at 2nd', 'oSFT3' => 'Sacrifice Fly - Out at 3rd', 'oSFT4' => 'Sacrifice Fly - Out at Home', 'oST2' => 'Single - Out at 2nd', 'oST3' => 'Single - Out at 3rd', 'oST4' => 'Single - Out at Home', 'oTT4' => 'Triple - Out at Home', } end |
.pitch_type(code) ⇒ Object
137 138 139 |
# File 'lib/sportradar/api/baseball/pitch.rb', line 137 def self.pitch_type(code) pitch_types[code] end |
.pitch_types ⇒ Object
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/sportradar/api/baseball/pitch.rb', line 141 def self.pitch_types @pitch_types ||= { 'FA' => 'Fastball', 'SI' => 'Sinker', 'CT' => 'Cutter', 'CU' => 'Curveball', 'SL' => 'Slider', 'CH' => 'Changeup', 'KN' => 'Knuckleball', 'SP' => 'Splitter', 'SC' => 'Screwball', 'FO' => 'Forkball', 'IB' => 'Intentional Ball', 'PI' => 'Pitchout', } end |
Instance Method Details
#==(other) ⇒ Object
17 18 19 |
# File 'lib/sportradar/api/baseball/pitch.rb', line 17 def ==(other) @id == other.id && @count == other.count && @outcome_id == other.outcome_id end |
#ball? ⇒ Boolean
56 57 58 |
# File 'lib/sportradar/api/baseball/pitch.rb', line 56 def ball? ['bAB', 'bB', 'bDB', 'bIB', 'bPO'].include? @outcome_id end |
#foul? ⇒ Boolean
52 53 54 |
# File 'lib/sportradar/api/baseball/pitch.rb', line 52 def foul? ['kF','kFT'].include? @outcome_id end |
#hit_ends_ab? ⇒ Boolean
64 65 66 |
# File 'lib/sportradar/api/baseball/pitch.rb', line 64 def hit_ends_ab? @hit_location.present? && !foul? end |
#homerun? ⇒ Boolean
48 49 50 |
# File 'lib/sportradar/api/baseball/pitch.rb', line 48 def homerun? @outcome_id == 'aHR' end |
#parse_count(data) ⇒ Object
107 108 109 110 111 112 113 |
# File 'lib/sportradar/api/baseball/pitch.rb', line 107 def parse_count(data) @count = data @balls = data['balls'] if data['balls'] @strikes = data['strikes'] if data['strikes'] @outs = data['outs'] if data['outs'] @atbat_pitch_count = data['pitch_count'] if data['pitch_count'] end |
#parse_errors(data) ⇒ Object
77 78 79 |
# File 'lib/sportradar/api/baseball/pitch.rb', line 77 def parse_errors(data) @errors = data.map { |hash| Error.new(hash) } end |
#parse_fielders(data) ⇒ Object
81 82 83 |
# File 'lib/sportradar/api/baseball/pitch.rb', line 81 def parse_fielders(data) @fielders = data.map { |hash| Fielder.new(hash) } end |
#parse_flags(data) ⇒ Object
96 97 98 99 100 101 102 103 104 105 |
# File 'lib/sportradar/api/baseball/pitch.rb', line 96 def parse_flags(data) @is_ab_over = data['is_ab_over'] if data['is_ab_over'] @is_bunt = data['is_bunt'] if data['is_bunt'] @is_bunt_shown = data['is_bunt_shown'] if data['is_bunt_shown'] @is_hit = data['is_hit'] if data['is_hit'] @is_wild_pitch = data['is_wild_pitch'] if data['is_wild_pitch'] @is_passed_ball = data['is_passed_ball'] if data['is_passed_ball'] @is_double_play = data['is_double_play'] if data['is_double_play'] @is_triple_play = data['is_triple_play'] if data['is_triple_play'] end |
#parse_hit(data) ⇒ Object
68 69 70 71 |
# File 'lib/sportradar/api/baseball/pitch.rb', line 68 def parse_hit(data) @hit_type = data['hit_type'] if data['hit_type'] @hit_location = data['hit_location'] if data['hit_location'] end |
#parse_pitcher(data) ⇒ Object
85 86 87 88 89 90 91 92 93 94 |
# File 'lib/sportradar/api/baseball/pitch.rb', line 85 def parse_pitcher(data) @type = data['pitch_type'] if data['pitch_type'] @speed = data['pitch_speed'] if data['pitch_speed'] @x = data['pitch_x'] if data['pitch_x'] @y = data['pitch_y'] if data['pitch_y'] @zone = data['pitch_zone'] if data['pitch_zone'] @pitch_type_name = self.class.pitch_type(@type) @total_pitch_count = data['pitch_count'] if data['pitch_count'] end |
#parse_runners(data) ⇒ Object
73 74 75 |
# File 'lib/sportradar/api/baseball/pitch.rb', line 73 def parse_runners(data) @runners = data.map { |hash| Runner.new(hash) } end |
#parse_steal(data) ⇒ Object
126 127 128 |
# File 'lib/sportradar/api/baseball/pitch.rb', line 126 def parse_steal(data) end |
#parse_warming_up(data) ⇒ Object
115 116 117 118 119 120 121 122 123 124 |
# File 'lib/sportradar/api/baseball/pitch.rb', line 115 def parse_warming_up(data) @warming_id = data['id'] @warming_player_id = data['player_id'] @warming_team_id = data['team_id'] @warming_last_name = data['last_name'] @warming_first_name = data['first_name'] @warming_preferred_name = data['preferred_name'] @warming_jersey_number = data['jersey_number'] @warming_up = "#{data['preferred_name'] || data['first_name']} #{data['last_name']}" end |
#pitches ⇒ Object
44 45 46 |
# File 'lib/sportradar/api/baseball/pitch.rb', line 44 def pitches @pitches_hash.values end |
#strike? ⇒ Boolean
60 61 62 |
# File 'lib/sportradar/api/baseball/pitch.rb', line 60 def strike? ['aKLAD1', 'aKLAD2', 'aKLAD3', 'aKLAD4', 'aKSAD1', 'aKSAD2', 'aKSAD3', 'aKSAD4', 'kF', 'kFT', 'kKL', 'kKS', 'oKLT1', 'oKLT2', 'oKLT3', 'oKLT4', 'oKST1', 'oKST2', 'oKST3', 'oKST4'].include? @outcome_id end |
#update(data, **opts) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/sportradar/api/baseball/pitch.rb', line 20 def update(data, **opts) if data['outcome_id'] @outcome_id = data['outcome_id'] @outcome = self.class.pitch_outcome(@outcome_id) end @description = data['description'] if data['description'] @status = data['status'] if data['status'] @created_at = data['created_at'] if data['created_at'] parse_hit(data) parse_runners(data['runners']) if data['runners'] parse_pitcher(data['pitcher']) if data['pitcher'] parse_flags(data['flags']) if data['flags'] parse_count(data['count']) if data['count'] parse_warming_up(data['warming_up']) if data['warming_up'] parse_fielders(data['fielders']) if data['fielders'] parse_errors(data['errors']) if data['errors'] end |
#updated ⇒ Object
40 41 42 |
# File 'lib/sportradar/api/baseball/pitch.rb', line 40 def updated @created_at end |