Class: Pitcher

Inherits:
Player show all
Defined in:
lib/pitcher.rb

Overview

This class represents a single pitcher whom appeared in an MLB game

Instance Attribute Summary collapse

Attributes inherited from Player

#appearances, #avg, #bat_order, #boxname, #era, #first, #game_position, #games, #hr, #last, #losses, #num, #rbi, #rl, #saves, #status, #std_hr, #team_code, #team_obj, #type, #wins

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Player

#at_bats_count, #get_all_appearances, #get_games_for_season, #get_team, #init, #init_pitcher_from_scoreboard

Instance Attribute Details

#batsObject

Returns the value of attribute bats.



8
9
10
# File 'lib/pitcher.rb', line 8

def bats
  @bats
end

#dobObject

Returns the value of attribute dob.



8
9
10
# File 'lib/pitcher.rb', line 8

def dob
  @dob
end

#first_nameObject

attributes read from the pitchers/(pid).xml file



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

def first_name
  @first_name
end

#gameObject

Returns the value of attribute game.



12
13
14
# File 'lib/pitcher.rb', line 12

def game
  @game
end

#gidObject

attributes read from the pitchers/(pid).xml file



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

def gid
  @gid
end

#heightObject

Returns the value of attribute height.



8
9
10
# File 'lib/pitcher.rb', line 8

def height
  @height
end

#jersey_numberObject

attributes read from the pitchers/(pid).xml file



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

def jersey_number
  @jersey_number
end

#last_nameObject

attributes read from the pitchers/(pid).xml file



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

def last_name
  @last_name
end

#opponent_careerObject

Returns the value of attribute opponent_career.



9
10
11
# File 'lib/pitcher.rb', line 9

def opponent_career
  @opponent_career
end

#opponent_emptyObject

Returns the value of attribute opponent_empty.



9
10
11
# File 'lib/pitcher.rb', line 9

def opponent_empty
  @opponent_empty
end

#opponent_loadedObject

Returns the value of attribute opponent_loaded.



10
11
12
# File 'lib/pitcher.rb', line 10

def opponent_loaded
  @opponent_loaded
end

#opponent_men_onObject

Returns the value of attribute opponent_men_on.



9
10
11
# File 'lib/pitcher.rb', line 9

def opponent_men_on
  @opponent_men_on
end

#opponent_rispObject

Returns the value of attribute opponent_risp.



9
10
11
# File 'lib/pitcher.rb', line 9

def opponent_risp
  @opponent_risp
end

#opponent_seasonObject

Returns the value of attribute opponent_season.



9
10
11
# File 'lib/pitcher.rb', line 9

def opponent_season
  @opponent_season
end

#opponent_vs_lObject

Returns the value of attribute opponent_vs_l.



10
11
12
# File 'lib/pitcher.rb', line 10

def opponent_vs_l
  @opponent_vs_l
end

#opponent_vs_rObject

Returns the value of attribute opponent_vs_r.



10
11
12
# File 'lib/pitcher.rb', line 10

def opponent_vs_r
  @opponent_vs_r
end

#pidObject

attributes read from the pitchers/(pid).xml file



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

def pid
  @pid
end

#positionObject

Returns the value of attribute position.



8
9
10
# File 'lib/pitcher.rb', line 8

def position
  @position
end

#team_abbrevObject

attributes read from the pitchers/(pid).xml file



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

def team_abbrev
  @team_abbrev
end

#throwsObject

Returns the value of attribute throws.



8
9
10
# File 'lib/pitcher.rb', line 8

def throws
  @throws
end

#weightObject

Returns the value of attribute weight.



8
9
10
# File 'lib/pitcher.rb', line 8

def weight
  @weight
end

Class Method Details

.get_all_ids_for_game(gid) ⇒ Object

Returns an array of pitcher ids for the game specified pitchers are found by looking in the gid/pitchers directory on gameday



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/pitcher.rb', line 79

def self.get_all_ids_for_game(gid)
  pitchers_page = GamedayFetcher.fetch_pitchers_page(gid)
  results = []
  if pitchers_page
    doc = Hpricot(pitchers_page)
    a = doc.at('ul')  
    if a
      (a/"a").each do |link|
        # look at each link inside of a ul tag
        if link.inner_html.include?(".xml") == true
          # if the link contains the text '.xml' then it is a pitcher
          str = link.inner_html
          str.strip!
          pid = str[0..str.length-5]
          results << pid
        end
      end
    end
  end
  results
end

Instance Method Details

#get_all_starts(year) ⇒ Object

Returns an array of PitchingAppearance objects for all of the pitchers starts



36
37
38
39
40
41
42
# File 'lib/pitcher.rb', line 36

def get_all_starts(year)
  results = []
  app = get_all_appearances(year)
  if app.start == true
    results << app
  end
end

#get_gameObject



69
70
71
72
73
74
# File 'lib/pitcher.rb', line 69

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



59
60
61
62
63
64
65
66
# File 'lib/pitcher.rb', line 59

def get_pitches
  results = []
  ab = get_vs_ab
  ab.each do |ab|
    results << ab.pitches
  end
  results.flatten
end

#get_vs_abObject

Returns an array of the atbats against this pitcher during this game



46
47
48
49
50
51
52
53
54
55
# File 'lib/pitcher.rb', line 46

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

#load_from_id(gid, pid) ⇒ Object

Loads a Pitcher object given a game id and a player id



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/pitcher.rb', line 16

def load_from_id(gid, pid)
  @gid = gid
  @pid = pid
  @position = 'P'
  @xml_data = GamedayFetcher.fetch_pitcher(gid, pid)
  @xml_doc = REXML::Document.new(@xml_data)
  @team_abbrev = @xml_doc.root.attributes["team"]
  @first_name = @xml_doc.root.attributes["first_name"]
  @last_name = @xml_doc.root.attributes["last_name"]
  @jersey_number = @xml_doc.root.attributes["jersey_number"]
  @height = @xml_doc.root.attributes["height"]
  @weight = @xml_doc.root.attributes["weight"]
  @bats = @xml_doc.root.attributes["bats"]
  @throws = @xml_doc.root.attributes["throws"]
  @dob = @xml_doc.root.attributes['dob']
  set_opponent_stats
end