Class: Pitch

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

Overview

This class represents a single pitch in an MLB baseball game. Most of the attributes represent the physics of the pitch thrown.

Pitch Type Codes

FS = Splitter
SL = Slider
FF = Fastball
SI = Sinker
CH = Change
FA = Fastball
CU = Curve
FC = Cutter
KN = Knuckle
KC = Knuckle Curve

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#ab_numObject

Returns the value of attribute ab_num.



19
20
21
# File 'lib/pitch.rb', line 19

def ab_num
  @ab_num
end

#axObject

Returns the value of attribute ax.



22
23
24
# File 'lib/pitch.rb', line 22

def ax
  @ax
end

#ayObject

Returns the value of attribute ay.



22
23
24
# File 'lib/pitch.rb', line 22

def ay
  @ay
end

#azObject

Returns the value of attribute az.



22
23
24
# File 'lib/pitch.rb', line 22

def az
  @az
end

#batter_idObject

Returns the value of attribute batter_id.



19
20
21
# File 'lib/pitch.rb', line 19

def batter_id
  @batter_id
end

#break_angleObject

Returns the value of attribute break_angle.



22
23
24
# File 'lib/pitch.rb', line 22

def break_angle
  @break_angle
end

#break_lengthObject

Returns the value of attribute break_length.



22
23
24
# File 'lib/pitch.rb', line 22

def break_length
  @break_length
end

#break_yObject

Returns the value of attribute break_y.



22
23
24
# File 'lib/pitch.rb', line 22

def break_y
  @break_y
end

#desObject

Returns the value of attribute des.



20
21
22
# File 'lib/pitch.rb', line 20

def des
  @des
end

#end_speedObject

Returns the value of attribute end_speed.



20
21
22
# File 'lib/pitch.rb', line 20

def end_speed
  @end_speed
end

#gidObject

Returns the value of attribute gid.



19
20
21
# File 'lib/pitch.rb', line 19

def gid
  @gid
end

#on_1bObject

Returns the value of attribute on_1b.



23
24
25
# File 'lib/pitch.rb', line 23

def on_1b
  @on_1b
end

#on_2bObject

Returns the value of attribute on_2b.



23
24
25
# File 'lib/pitch.rb', line 23

def on_2b
  @on_2b
end

#on_3bObject

Returns the value of attribute on_3b.



23
24
25
# File 'lib/pitch.rb', line 23

def on_3b
  @on_3b
end

#pfx_xObject

Returns the value of attribute pfx_x.



21
22
23
# File 'lib/pitch.rb', line 21

def pfx_x
  @pfx_x
end

#pfx_zObject

Returns the value of attribute pfx_z.



21
22
23
# File 'lib/pitch.rb', line 21

def pfx_z
  @pfx_z
end

#pitch_idObject

Returns the value of attribute pitch_id.



20
21
22
# File 'lib/pitch.rb', line 20

def pitch_id
  @pitch_id
end

#pitch_typeObject

Returns the value of attribute pitch_type.



22
23
24
# File 'lib/pitch.rb', line 22

def pitch_type
  @pitch_type
end

#pitcher_idObject

Returns the value of attribute pitcher_id.



19
20
21
# File 'lib/pitch.rb', line 19

def pitcher_id
  @pitcher_id
end

#pxObject

Returns the value of attribute px.



21
22
23
# File 'lib/pitch.rb', line 21

def px
  @px
end

#pzObject

Returns the value of attribute pz.



21
22
23
# File 'lib/pitch.rb', line 21

def pz
  @pz
end

#spin_dirObject

Returns the value of attribute spin_dir.



23
24
25
# File 'lib/pitch.rb', line 23

def spin_dir
  @spin_dir
end

#spin_rateObject

Returns the value of attribute spin_rate.



23
24
25
# File 'lib/pitch.rb', line 23

def spin_rate
  @spin_rate
end

#start_speedObject

Returns the value of attribute start_speed.



20
21
22
# File 'lib/pitch.rb', line 20

def start_speed
  @start_speed
end

#sv_idObject

Returns the value of attribute sv_id.



20
21
22
# File 'lib/pitch.rb', line 20

def sv_id
  @sv_id
end

#sz_botObject

Returns the value of attribute sz_bot.



21
22
23
# File 'lib/pitch.rb', line 21

def sz_bot
  @sz_bot
end

#sz_topObject

Returns the value of attribute sz_top.



21
22
23
# File 'lib/pitch.rb', line 21

def sz_top
  @sz_top
end

#typeObject

Returns the value of attribute type.



20
21
22
# File 'lib/pitch.rb', line 20

def type
  @type
end

#type_confidenceObject

Returns the value of attribute type_confidence.



22
23
24
# File 'lib/pitch.rb', line 22

def type_confidence
  @type_confidence
end

#vx0Object

Returns the value of attribute vx0.



21
22
23
# File 'lib/pitch.rb', line 21

def vx0
  @vx0
end

#vy0Object

Returns the value of attribute vy0.



21
22
23
# File 'lib/pitch.rb', line 21

def vy0
  @vy0
end

#vz0Object

Returns the value of attribute vz0.



21
22
23
# File 'lib/pitch.rb', line 21

def vz0
  @vz0
end

#xObject

Returns the value of attribute x.



20
21
22
# File 'lib/pitch.rb', line 20

def x
  @x
end

#x0Object

Returns the value of attribute x0.



21
22
23
# File 'lib/pitch.rb', line 21

def x0
  @x0
end

#yObject

Returns the value of attribute y.



20
21
22
# File 'lib/pitch.rb', line 20

def y
  @y
end

#y0Object

Returns the value of attribute y0.



21
22
23
# File 'lib/pitch.rb', line 21

def y0
  @y0
end

#z0Object

Returns the value of attribute z0.



21
22
23
# File 'lib/pitch.rb', line 21

def z0
  @z0
end

Class Method Details

.get_pitch_name(code) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/pitch.rb', line 62

def self.get_pitch_name(code)
  case code
  when 'FS'
    'Splitter'
  when 'SL'
    'Slider'
  when 'FF'
    'Fastball' # 4 seam
  when 'FT'
    'Fastball' # 2 seam
  when 'SI'
    'Sinker'
  when 'CH'
    'Change'
  when 'FA'
    'Fastball'
  when 'CU'
    'Curve'
  when 'FC'
    'Cutter'
  when 'KN'
    'Knuckle'
  when 'KC'
    'Knuckle Curve'
  else
    code
  end
end

Instance Method Details

#init(element) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/pitch.rb', line 25

def init(element)
  @des = element.attributes["des"]
  @pitch_id = element.attributes["id"]
  @type = element.attributes["type"]
  @x = element.attributes["x"]
  @y = element.attributes["y"]
  @sv_id = element.attributes["sv_id"]
  @start_speed = element.attributes["start_speed"]
  @end_speed = element.attributes["end_speed"]
  @sz_top = element.attributes["sz_top"]
  @sz_bot = element.attributes["sz_bot"]
  @pfx_x = element.attributes["pfx_x"]
  @pfx_z = element.attributes["pfx_z"]
  @px = element.attributes["px"]
  @pz = element.attributes["pz"]
  @x0 = element.attributes["x0"]
  @y0 = element.attributes["y0"]
  @z0 = element.attributes["z0"]
  @vx0 = element.attributes["vx0"]
  @vy0 = element.attributes["vy0"]
  @vz0 = element.attributes["vz0"]
  @ax = element.attributes["ax"]
  @ay = element.attributes["ay"]
  @az = element.attributes["az"]
  @break_y = element.attributes["break_y"]
  @break_angle = element.attributes["break_angle"]
  @break_length = element.attributes["break_length"]
  @pitch_type = element.attributes["pitch_type"]
  @type_confidence = element.attributes["type_confidence"]
  @spin_dir = element.attributes["spin_dir"]
  @spin_rate = element.attributes["spin_rate"]
  @on_1b = element.attributes["on_1b"]
  @on_2b = element.attributes["on_2b"]
  @on_3b = element.attributes["on_3b"]
end