Class: Stattleship::Models::Pitch

Inherits:
OpenStruct
  • Object
show all
Defined in:
lib/stattleship/models/pitch.rb

Instance Method Summary collapse

Instance Method Details

#at_bat?Boolean

Returns:

  • (Boolean)

32
33
34
# File 'lib/stattleship/models/pitch.rb', line 32

def at_bat?
  is_at_bat
end

#at_bat_over?Boolean

Returns:

  • (Boolean)

36
37
38
# File 'lib/stattleship/models/pitch.rb', line 36

def at_bat_over?
  is_at_bat_over
end

#bunt?Boolean

Returns:

  • (Boolean)

40
41
42
# File 'lib/stattleship/models/pitch.rb', line 40

def bunt?
  is_bunt
end

#bunt_shown?Boolean

Returns:

  • (Boolean)

44
45
46
# File 'lib/stattleship/models/pitch.rb', line 44

def bunt_shown?
  is_bunt_shown
end

#descriptionObject


110
111
112
# File 'lib/stattleship/models/pitch.rb', line 110

def description
  [pitch_description, hit_description].compact.join("\n\n")
end

#double_play?Boolean

Returns:

  • (Boolean)

48
49
50
# File 'lib/stattleship/models/pitch.rb', line 48

def double_play?
  is_double_play
end

#dumpObject


255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
# File 'lib/stattleship/models/pitch.rb', line 255

def dump
  {
    id: id,
    at_bat_balls: at_bat_balls,
    at_bat_outs: at_bat_outs,
    at_bat_pitch_count: at_bat_pitch_count,
    at_bat_strikes: at_bat_strikes,
    description: description,
    even_count: even_count,
    event_id: event_id,
    full_count: full_count,
    game_id: game_id,
    half: half,
    hit_description: hit_description,
    hit_location: hit_location,
    hit_location_name: hit_location_name,
    hit_type: hit_type,
    hitter_id: hitter_id,
    hitter_name: hitter_name,
    hitter_pitch_count: hitter_pitch_count,
    hitter_team_id: hitter_team_id,
    hitter_team_name: hitter_team_name,
    inning: inning,
    inning_label: inning_label,
    is_at_bat: is_at_bat,
    is_at_bat_over: is_at_bat_over,
    is_bunt: is_bunt,
    is_bunt_shown: is_bunt_shown,
    is_double_play: is_double_play,
    is_hit: is_hit,
    is_on_base: is_on_base,
    is_passed_ball: is_passed_ball,
    is_triple_play: is_triple_play,
    is_wild_pitch: is_wild_pitch,
    ordinal_inning: ordinal_inning,
    pitch_count: pitch_count,
    pitch_description: pitch_description,
    pitch_name: pitch_name,
    pitch_outcome: pitch_outcome,
    pitch_outcome_type: pitch_outcome_type,
    pitch_speed: pitch_speed,
    pitch_type: pitch_type,
    pitch_zone: pitch_zone,
    pitched_at: pitched_at,
    pitcher_id: pitcher_id,
    pitcher_name: pitcher_name,
    sequence: sequence,
    team_id: team_id,
    team_name: team_name,
  }
end

#even_count?Boolean

Returns:

  • (Boolean)

72
73
74
75
76
77
78
# File 'lib/stattleship/models/pitch.rb', line 72

def even_count?
  if at_bat_pitch_count > 0
    at_bat_balls == at_bat_strikes
  else
    false
  end
end

#full_count?Boolean

Returns:

  • (Boolean)

80
81
82
83
# File 'lib/stattleship/models/pitch.rb', line 80

def full_count?
  (at_bat_balls == 3) &&
  (at_bat_strikes == 2)
end

#hit?Boolean

Returns:

  • (Boolean)

52
53
54
# File 'lib/stattleship/models/pitch.rb', line 52

def hit?
  is_hit
end

#hit_descriptionObject


225
226
227
228
229
230
231
# File 'lib/stattleship/models/pitch.rb', line 225

def hit_description
  if is_hit?
    "#{hit_name}#{hit_location_name}."
  else
    "#{hit_name}#{hit_location_name}." if hit_location_name
  end
end

#hit_location_nameObject


148
149
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
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
# File 'lib/stattleship/models/pitch.rb', line 148

def hit_location_name
  case hit_location
  when '1'
    ' to left'
  when '2'
    ' to left center'
  when '3'
    ' to center'
  when '4'
    ' to right center'
  when '5'
    ' to right'
  when '6'
    ' to deep left field'
  when '7'
    ' to deep left center'
  when '8'
    ' to deep center field'
  when '9'
    ' to deep right center'
  when '10'
    ' to deep right field'
  when '11'
    ' to left field'
  when '12'
    ' to left center alley'
  when '13'
    ' to center field'
  when '14'
    ' to right center alley'
  when '15'
    ' to right field'
  when '16'
    ' to shallow left field'
  when '17'
    ' to shallow left center'
  when '18'
    ' to shallow center'
  when '19'
    ' to shallow right center'
  when '20'
    ' to shallow right'
  when '21'
    ' to third'
  when '22'
    ' to short'
  when '23'
    ' to second'
  when '24'
    ' to first'
  when '25'
    ' to left infield grass'
  when '26'
    ' to right infield grass'
  when '27'
    ' to pitcher'
  when '28'
    " to catcher's left"
  when '29'
    ' infront of the catcher'
  when '30'
    " to catcher's right"
  when '31'
    ' to left field foul'
  when '32'
    ' to third base foul'
  when '33'
    'behind the catcher'
  when '34'
    ' to first base foul'
  when '35'
    ' to right field foul'
  else
    nil
  end
end

#hit_nameObject


133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/stattleship/models/pitch.rb', line 133

def hit_name
  case hit_type
  when 'GB'
    'Ground Ball'
  when 'FB'
    'Fly Ball'
  when 'PU'
    'Pop Fly'
  when 'LD'
    'Line Drive'
  else
    'Hit'
  end
end

#hitter_nameObject


14
15
16
17
18
# File 'lib/stattleship/models/pitch.rb', line 14

def hitter_name
  if hitter
    hitter.full_name
  end
end

#hitter_pitch_countObject


85
86
87
# File 'lib/stattleship/models/pitch.rb', line 85

def hitter_pitch_count
  "#{at_bat_balls}-#{at_bat_strikes}"
end

#hitter_team_nameObject


20
21
22
23
24
# File 'lib/stattleship/models/pitch.rb', line 20

def hitter_team_name
  if hitter_team
    hitter_team.name
  end
end

#inning_half_labelObject


89
90
91
92
93
94
95
96
97
98
# File 'lib/stattleship/models/pitch.rb', line 89

def inning_half_label
  case half
  when 'B'
    'Bottom of'
  when 'T'
    'Top of'
  else
    ''
  end
end

#inning_labelObject


104
105
106
107
108
# File 'lib/stattleship/models/pitch.rb', line 104

def inning_label
  if inning
    "#{inning_half_label} #{ordinal_inning}"
  end
end

#on_base?Boolean

Returns:

  • (Boolean)

56
57
58
# File 'lib/stattleship/models/pitch.rb', line 56

def on_base?
  is_on_base
end

#ordinal_inningObject


100
101
102
# File 'lib/stattleship/models/pitch.rb', line 100

def ordinal_inning
  inning.ordinalize
end

#passed_ball?Boolean

Returns:

  • (Boolean)

60
61
62
# File 'lib/stattleship/models/pitch.rb', line 60

def passed_ball?
  is_passed_ball
end

#pitch_descriptionObject


114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/stattleship/models/pitch.rb', line 114

def pitch_description
  if (pitch_type != 'IB' && pitch_speed.to_i > 0)
    [
      "#{hitter_name} at bat. #{pitcher_name} throws a #{pitch_speed.to_i} mph #{pitch_name}. #{pitch_outcome}.",
      "#{hitter_name} batting. #{pitcher_name} with a #{pitch_speed.to_i} mph #{pitch_name}. #{pitch_outcome}.",
      "#{pitcher_name} pitching to #{hitter_name}. #{pitch_speed.to_i} mph #{pitch_name} for a #{pitch_outcome}.",
      "#{pitcher_name} throws a #{pitch_speed.to_i} mph #{pitch_name} to #{hitter_name}. #{pitch_outcome}.",
    ].sample
  elsif pitch_type == 'IB'
    "#{pitcher_name} pitching to #{hitter_name}. #{pitch_name}."
  elsif !pitch_name == ''
    "#{hitter_name} up to bat. #{pitcher_name} throws a #{pitch_name} to #{hitter_name}."
  elsif !pitch_outcome == ''
    "#{pitcher_name} pitching to #{hitter_name}. #{pitch_outcome}."
  else
    "#{pitcher_name} pitching to #{hitter_name}."
  end
end

#pitcher_nameObject


8
9
10
11
12
# File 'lib/stattleship/models/pitch.rb', line 8

def pitcher_name
  if pitcher
    pitcher.full_name
  end
end

#team_nameObject


26
27
28
29
30
# File 'lib/stattleship/models/pitch.rb', line 26

def team_name
  if team
    team.name
  end
end

#titleObject


233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
# File 'lib/stattleship/models/pitch.rb', line 233

def title
  @title = []

  @title << game.scoreline
  @title << inning_label

  unless hitter_pitch_count == '0-0'
    @title << "#{hitter_pitch_count} count"
  end

  if at_bat_outs && at_bat_outs > 0
    @title << "#{h.pluralize(at_bat_outs, 'out')}"
  end

  if pitch_count && pitch_count > 0
    @title << "#{pitch_count.ordinalize} pitch"
  end

  @title.join(' | ')
end

#to_sentenceObject


4
5
6
# File 'lib/stattleship/models/pitch.rb', line 4

def to_sentence
  description
end

#triple_play?Boolean

Returns:

  • (Boolean)

64
65
66
# File 'lib/stattleship/models/pitch.rb', line 64

def triple_play?
  is_triple_play
end

#wild_pitch?Boolean

Returns:

  • (Boolean)

68
69
70
# File 'lib/stattleship/models/pitch.rb', line 68

def wild_pitch?
  is_wild_pitch
end