Class: PitchingAppearance

Inherits:
Object
  • Object
show all
Defined in:
lib/pitching_appearance.rb

Overview

This class holds data that represents a single pitching appearance by a pitcher.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#bObject

Returns the value of attribute b.



7
8
9
# File 'lib/pitching_appearance.rb', line 7

def b
  @b
end

#bbObject

Returns the value of attribute bb.



5
6
7
# File 'lib/pitching_appearance.rb', line 5

def bb
  @bb
end

#bfObject

Returns the value of attribute bf.



5
6
7
# File 'lib/pitching_appearance.rb', line 5

def bf
  @bf
end

#erObject

Returns the value of attribute er.



5
6
7
# File 'lib/pitching_appearance.rb', line 5

def er
  @er
end

#eraObject

Returns the value of attribute era.



6
7
8
# File 'lib/pitching_appearance.rb', line 6

def era
  @era
end

#gameObject

Returns the value of attribute game.



6
7
8
# File 'lib/pitching_appearance.rb', line 6

def game
  @game
end

#gidObject

Returns the value of attribute gid.



5
6
7
# File 'lib/pitching_appearance.rb', line 5

def gid
  @gid
end

#hObject

Returns the value of attribute h.



5
6
7
# File 'lib/pitching_appearance.rb', line 5

def h
  @h
end

#hrObject

Returns the value of attribute hr.



5
6
7
# File 'lib/pitching_appearance.rb', line 5

def hr
  @hr
end

#innObject

Returns the value of attribute inn.



5
6
7
# File 'lib/pitching_appearance.rb', line 5

def inn
  @inn
end

#lObject

Returns the value of attribute l.



6
7
8
# File 'lib/pitching_appearance.rb', line 6

def l
  @l
end

#max_speedObject

Returns the value of attribute max_speed.



7
8
9
# File 'lib/pitching_appearance.rb', line 7

def max_speed
  @max_speed
end

#min_speedObject

Returns the value of attribute min_speed.



7
8
9
# File 'lib/pitching_appearance.rb', line 7

def min_speed
  @min_speed
end

#noteObject

Returns the value of attribute note.



6
7
8
# File 'lib/pitching_appearance.rb', line 6

def note
  @note
end

#outObject

Returns the value of attribute out.



5
6
7
# File 'lib/pitching_appearance.rb', line 5

def out
  @out
end

#pidObject

Returns the value of attribute pid.



5
6
7
# File 'lib/pitching_appearance.rb', line 5

def pid
  @pid
end

#pitcher_nameObject

Returns the value of attribute pitcher_name.



5
6
7
# File 'lib/pitching_appearance.rb', line 5

def pitcher_name
  @pitcher_name
end

#pitchesObject

Returns the value of attribute pitches.



7
8
9
# File 'lib/pitching_appearance.rb', line 7

def pitches
  @pitches
end

#rObject

Returns the value of attribute r.



5
6
7
# File 'lib/pitching_appearance.rb', line 5

def r
  @r
end

#sObject

Returns the value of attribute s.



7
8
9
# File 'lib/pitching_appearance.rb', line 7

def s
  @s
end

#soObject

Returns the value of attribute so.



5
6
7
# File 'lib/pitching_appearance.rb', line 5

def so
  @so
end

#startObject

Returns the value of attribute start.



6
7
8
# File 'lib/pitching_appearance.rb', line 6

def start
  @start
end

#wObject

Returns the value of attribute w.



6
7
8
# File 'lib/pitching_appearance.rb', line 6

def w
  @w
end

#xObject

Returns the value of attribute x.



7
8
9
# File 'lib/pitching_appearance.rb', line 7

def x
  @x
end

Instance Method Details

#get_gameObject



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_pitchesObject

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_abObject

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_countObject



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

Returns:

  • (Boolean)


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_statsObject



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

Returns:

  • (Boolean)


37
38
39
# File 'lib/pitching_appearance.rb', line 37

def start?
  start
end