class Stattleship::Models::Pitch
Public Instance Methods
at_bat?()
click to toggle source
# File lib/stattleship/models/pitch.rb, line 32 def at_bat? is_at_bat end
at_bat_over?()
click to toggle source
# File lib/stattleship/models/pitch.rb, line 36 def at_bat_over? is_at_bat_over end
bunt?()
click to toggle source
# File lib/stattleship/models/pitch.rb, line 40 def bunt? is_bunt end
bunt_shown?()
click to toggle source
# File lib/stattleship/models/pitch.rb, line 44 def bunt_shown? is_bunt_shown end
description()
click to toggle source
# File lib/stattleship/models/pitch.rb, line 110 def description [pitch_description, hit_description].compact.join("\n\n") end
double_play?()
click to toggle source
# File lib/stattleship/models/pitch.rb, line 48 def double_play? is_double_play end
dump()
click to toggle source
# 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?()
click to toggle source
# 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?()
click to toggle source
# File lib/stattleship/models/pitch.rb, line 80 def full_count? (at_bat_balls == 3) && (at_bat_strikes == 2) end
hit?()
click to toggle source
# File lib/stattleship/models/pitch.rb, line 52 def hit? is_hit end
hit_description()
click to toggle source
# 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_name()
click to toggle source
# 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_name()
click to toggle source
# 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_name()
click to toggle source
# File lib/stattleship/models/pitch.rb, line 14 def hitter_name if hitter hitter.full_name end end
hitter_pitch_count()
click to toggle source
# File lib/stattleship/models/pitch.rb, line 85 def hitter_pitch_count "#{at_bat_balls}-#{at_bat_strikes}" end
hitter_team_name()
click to toggle source
# File lib/stattleship/models/pitch.rb, line 20 def hitter_team_name if hitter_team hitter_team.name end end
inning_half_label()
click to toggle source
# 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_label()
click to toggle source
# File lib/stattleship/models/pitch.rb, line 104 def inning_label if inning "#{inning_half_label} #{ordinal_inning}" end end
on_base?()
click to toggle source
# File lib/stattleship/models/pitch.rb, line 56 def on_base? is_on_base end
ordinal_inning()
click to toggle source
# File lib/stattleship/models/pitch.rb, line 100 def ordinal_inning inning.ordinalize end
passed_ball?()
click to toggle source
# File lib/stattleship/models/pitch.rb, line 60 def passed_ball? is_passed_ball end
pitch_description()
click to toggle source
# 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_name()
click to toggle source
# File lib/stattleship/models/pitch.rb, line 8 def pitcher_name if pitcher pitcher.full_name end end
team_name()
click to toggle source
# File lib/stattleship/models/pitch.rb, line 26 def team_name if team team.name end end
title()
click to toggle source
# 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_sentence()
click to toggle source
# File lib/stattleship/models/pitch.rb, line 4 def to_sentence description end
triple_play?()
click to toggle source
# File lib/stattleship/models/pitch.rb, line 64 def triple_play? is_triple_play end
wild_pitch?()
click to toggle source
# File lib/stattleship/models/pitch.rb, line 68 def wild_pitch? is_wild_pitch end