Class: PitchingAppearance
- Inherits:
-
Object
- Object
- PitchingAppearance
- Defined in:
- lib/pitching_appearance.rb
Overview
This class holds data that represents a single pitching appearance by a pitcher.
Instance Attribute Summary collapse
-
#b ⇒ Object
Returns the value of attribute b.
-
#bb ⇒ Object
Returns the value of attribute bb.
-
#bf ⇒ Object
Returns the value of attribute bf.
-
#er ⇒ Object
Returns the value of attribute er.
-
#era ⇒ Object
Returns the value of attribute era.
-
#game ⇒ Object
Returns the value of attribute game.
-
#gid ⇒ Object
Returns the value of attribute gid.
-
#h ⇒ Object
Returns the value of attribute h.
-
#hr ⇒ Object
Returns the value of attribute hr.
-
#inn ⇒ Object
Returns the value of attribute inn.
-
#l ⇒ Object
Returns the value of attribute l.
-
#max_speed ⇒ Object
Returns the value of attribute max_speed.
-
#min_speed ⇒ Object
Returns the value of attribute min_speed.
-
#note ⇒ Object
Returns the value of attribute note.
-
#out ⇒ Object
Returns the value of attribute out.
-
#pid ⇒ Object
Returns the value of attribute pid.
-
#pitcher_name ⇒ Object
Returns the value of attribute pitcher_name.
-
#pitches ⇒ Object
Returns the value of attribute pitches.
-
#r ⇒ Object
Returns the value of attribute r.
-
#s ⇒ Object
Returns the value of attribute s.
-
#so ⇒ Object
Returns the value of attribute so.
-
#start ⇒ Object
Returns the value of attribute start.
-
#w ⇒ Object
Returns the value of attribute w.
-
#x ⇒ Object
Returns the value of attribute x.
Instance Method Summary collapse
- #get_game ⇒ Object
-
#get_pitches ⇒ Object
Returns an array of pitches thrown by this pitcher during this game.
-
#get_vs_ab ⇒ Object
Returns an array of the atbats against this pitcher during this game.
-
#init(gid, element, count) ⇒ Object
Used to initialize from box score data.
- #pitch_count ⇒ Object
-
#quality_start? ⇒ Boolean
Returns true if this was a quality start A quality start is defined as being greater than or equal to 6 innings and allowing 3 runs or less.
- #set_pitch_stats ⇒ Object
-
#start? ⇒ Boolean
Returns true if this appearance is a start.
Instance Attribute Details
#b ⇒ Object
Returns the value of attribute b.
7 8 9 |
# File 'lib/pitching_appearance.rb', line 7 def b @b end |
#bb ⇒ Object
Returns the value of attribute bb.
5 6 7 |
# File 'lib/pitching_appearance.rb', line 5 def bb @bb end |
#bf ⇒ Object
Returns the value of attribute bf.
5 6 7 |
# File 'lib/pitching_appearance.rb', line 5 def bf @bf end |
#er ⇒ Object
Returns the value of attribute er.
5 6 7 |
# File 'lib/pitching_appearance.rb', line 5 def er @er end |
#era ⇒ Object
Returns the value of attribute era.
6 7 8 |
# File 'lib/pitching_appearance.rb', line 6 def era @era end |
#game ⇒ Object
Returns the value of attribute game.
6 7 8 |
# File 'lib/pitching_appearance.rb', line 6 def game @game end |
#gid ⇒ Object
Returns the value of attribute gid.
5 6 7 |
# File 'lib/pitching_appearance.rb', line 5 def gid @gid end |
#h ⇒ Object
Returns the value of attribute h.
5 6 7 |
# File 'lib/pitching_appearance.rb', line 5 def h @h end |
#hr ⇒ Object
Returns the value of attribute hr.
5 6 7 |
# File 'lib/pitching_appearance.rb', line 5 def hr @hr end |
#inn ⇒ Object
Returns the value of attribute inn.
5 6 7 |
# File 'lib/pitching_appearance.rb', line 5 def inn @inn end |
#l ⇒ Object
Returns the value of attribute l.
6 7 8 |
# File 'lib/pitching_appearance.rb', line 6 def l @l end |
#max_speed ⇒ Object
Returns the value of attribute max_speed.
7 8 9 |
# File 'lib/pitching_appearance.rb', line 7 def max_speed @max_speed end |
#min_speed ⇒ Object
Returns the value of attribute min_speed.
7 8 9 |
# File 'lib/pitching_appearance.rb', line 7 def min_speed @min_speed end |
#note ⇒ Object
Returns the value of attribute note.
6 7 8 |
# File 'lib/pitching_appearance.rb', line 6 def note @note end |
#out ⇒ Object
Returns the value of attribute out.
5 6 7 |
# File 'lib/pitching_appearance.rb', line 5 def out @out end |
#pid ⇒ Object
Returns the value of attribute pid.
5 6 7 |
# File 'lib/pitching_appearance.rb', line 5 def pid @pid end |
#pitcher_name ⇒ Object
Returns the value of attribute pitcher_name.
5 6 7 |
# File 'lib/pitching_appearance.rb', line 5 def pitcher_name @pitcher_name end |
#pitches ⇒ Object
Returns the value of attribute pitches.
7 8 9 |
# File 'lib/pitching_appearance.rb', line 7 def pitches @pitches end |
#r ⇒ Object
Returns the value of attribute r.
5 6 7 |
# File 'lib/pitching_appearance.rb', line 5 def r @r end |
#s ⇒ Object
Returns the value of attribute s.
7 8 9 |
# File 'lib/pitching_appearance.rb', line 7 def s @s end |
#so ⇒ Object
Returns the value of attribute so.
5 6 7 |
# File 'lib/pitching_appearance.rb', line 5 def so @so end |
#start ⇒ Object
Returns the value of attribute start.
6 7 8 |
# File 'lib/pitching_appearance.rb', line 6 def start @start end |
#w ⇒ Object
Returns the value of attribute w.
6 7 8 |
# File 'lib/pitching_appearance.rb', line 6 def w @w end |
#x ⇒ Object
Returns the value of attribute x.
7 8 9 |
# File 'lib/pitching_appearance.rb', line 7 def x @x end |
Instance Method Details
#get_game ⇒ Object
103 104 105 106 107 108 |
# File 'lib/pitching_appearance.rb', line 103 def get_game if !@game @game = Game.new(@gid) end @game end |
#get_pitches ⇒ Object
Returns an array of pitches thrown by this pitcher during this game
66 67 68 69 70 71 72 73 |
# File 'lib/pitching_appearance.rb', line 66 def get_pitches @pitches = [] ab = get_vs_ab ab.each do |ab| @pitches << ab.pitches end @pitches.flatten! end |
#get_vs_ab ⇒ Object
Returns an array of the atbats against this pitcher during this game
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/pitching_appearance.rb', line 53 def get_vs_ab results = [] abs = get_game.get_atbats abs.each do |ab| if ab.pitcher_id == @pid results << ab end end results end |
#init(gid, element, count) ⇒ Object
Used to initialize from box score data
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/pitching_appearance.rb', line 10 def init(gid, element, count) @pitches = [] @gid = gid @pid = element.attributes['id'] @pitcher_name = element.attributes['name'] @out = element.attributes['out'] @inn = convert_out_to_inn(element.attributes['out']) @bf = element.attributes['bf'] @er = element.attributes['er'] @r = element.attributes['r'] @h = element.attributes['h'] @so = element.attributes['so'] @hr = element.attributes['hr'] @bb = element.attributes['bb'] @w = element.attributes['w'] @l = element.attributes['l'] @era = element.attributes['era'] @note = element.attributes['note'] if count == 1 @start = true else @start = false end end |
#pitch_count ⇒ Object
98 99 100 |
# File 'lib/pitching_appearance.rb', line 98 def pitch_count get_pitches.length end |
#quality_start? ⇒ Boolean
Returns true if this was a quality start A quality start is defined as being greater than or equal to 6 innings and allowing 3 runs or less
44 45 46 47 48 49 |
# File 'lib/pitching_appearance.rb', line 44 def quality_start? if @inn.to_i >= 6 && @r.to_i < 4 return true end return false end |
#set_pitch_stats ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/pitching_appearance.rb', line 76 def set_pitch_stats @b, @s, @x, @max_speed, @min_speed = 0, 0, 0, 0, 200 pitches = get_pitches pitches.each do |pitch| case pitch.type when 'B' @b += 1 when 'S' @s += 1 when 'X' @x += 1 end if pitch.start_speed.to_f > @max_speed @max_speed = pitch.start_speed.to_f end if pitch.start_speed.to_f < @min_speed @min_speed = pitch.start_speed.to_f end end end |
#start? ⇒ Boolean
Returns true if this appearance is a start
37 38 39 |
# File 'lib/pitching_appearance.rb', line 37 def start? start end |