Class: Pitcher
Overview
This class represents a single pitcher whom appeared in an MLB game
Instance Attribute Summary collapse
-
#bats ⇒ Object
Returns the value of attribute bats.
-
#dob ⇒ Object
Returns the value of attribute dob.
-
#first_name ⇒ Object
attributes read from the pitchers/(pid).xml file.
-
#game ⇒ Object
Returns the value of attribute game.
-
#gid ⇒ Object
attributes read from the pitchers/(pid).xml file.
-
#height ⇒ Object
Returns the value of attribute height.
-
#jersey_number ⇒ Object
attributes read from the pitchers/(pid).xml file.
-
#last_name ⇒ Object
attributes read from the pitchers/(pid).xml file.
-
#opponent_career ⇒ Object
Returns the value of attribute opponent_career.
-
#opponent_empty ⇒ Object
Returns the value of attribute opponent_empty.
-
#opponent_loaded ⇒ Object
Returns the value of attribute opponent_loaded.
-
#opponent_men_on ⇒ Object
Returns the value of attribute opponent_men_on.
-
#opponent_risp ⇒ Object
Returns the value of attribute opponent_risp.
-
#opponent_season ⇒ Object
Returns the value of attribute opponent_season.
-
#opponent_vs_l ⇒ Object
Returns the value of attribute opponent_vs_l.
-
#opponent_vs_r ⇒ Object
Returns the value of attribute opponent_vs_r.
-
#pid ⇒ Object
attributes read from the pitchers/(pid).xml file.
-
#position ⇒ Object
Returns the value of attribute position.
-
#team_abbrev ⇒ Object
attributes read from the pitchers/(pid).xml file.
-
#throws ⇒ Object
Returns the value of attribute throws.
-
#weight ⇒ Object
Returns the value of attribute weight.
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
-
.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.
Instance Method Summary collapse
-
#get_all_starts(year) ⇒ Object
Returns an array of PitchingAppearance objects for all of the pitchers starts.
- #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.
-
#load_from_id(gid, pid) ⇒ Object
Loads a Pitcher object given a game id and a player id.
Methods inherited from Player
#at_bats_count, #get_all_appearances, #get_games_for_season, #get_team, #init, #init_pitcher_from_scoreboard
Instance Attribute Details
#bats ⇒ Object
Returns the value of attribute bats.
8 9 10 |
# File 'lib/pitcher.rb', line 8 def bats @bats end |
#dob ⇒ Object
Returns the value of attribute dob.
8 9 10 |
# File 'lib/pitcher.rb', line 8 def dob @dob end |
#first_name ⇒ Object
attributes read from the pitchers/(pid).xml file
7 8 9 |
# File 'lib/pitcher.rb', line 7 def first_name @first_name end |
#game ⇒ Object
Returns the value of attribute game.
12 13 14 |
# File 'lib/pitcher.rb', line 12 def game @game end |
#gid ⇒ Object
attributes read from the pitchers/(pid).xml file
7 8 9 |
# File 'lib/pitcher.rb', line 7 def gid @gid end |
#height ⇒ Object
Returns the value of attribute height.
8 9 10 |
# File 'lib/pitcher.rb', line 8 def height @height end |
#jersey_number ⇒ Object
attributes read from the pitchers/(pid).xml file
7 8 9 |
# File 'lib/pitcher.rb', line 7 def jersey_number @jersey_number end |
#last_name ⇒ Object
attributes read from the pitchers/(pid).xml file
7 8 9 |
# File 'lib/pitcher.rb', line 7 def last_name @last_name end |
#opponent_career ⇒ Object
Returns the value of attribute opponent_career.
9 10 11 |
# File 'lib/pitcher.rb', line 9 def opponent_career @opponent_career end |
#opponent_empty ⇒ Object
Returns the value of attribute opponent_empty.
9 10 11 |
# File 'lib/pitcher.rb', line 9 def opponent_empty @opponent_empty end |
#opponent_loaded ⇒ Object
Returns the value of attribute opponent_loaded.
10 11 12 |
# File 'lib/pitcher.rb', line 10 def opponent_loaded @opponent_loaded end |
#opponent_men_on ⇒ Object
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_risp ⇒ Object
Returns the value of attribute opponent_risp.
9 10 11 |
# File 'lib/pitcher.rb', line 9 def opponent_risp @opponent_risp end |
#opponent_season ⇒ Object
Returns the value of attribute opponent_season.
9 10 11 |
# File 'lib/pitcher.rb', line 9 def opponent_season @opponent_season end |
#opponent_vs_l ⇒ Object
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_r ⇒ Object
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 |
#pid ⇒ Object
attributes read from the pitchers/(pid).xml file
7 8 9 |
# File 'lib/pitcher.rb', line 7 def pid @pid end |
#position ⇒ Object
Returns the value of attribute position.
8 9 10 |
# File 'lib/pitcher.rb', line 8 def position @position end |
#team_abbrev ⇒ Object
attributes read from the pitchers/(pid).xml file
7 8 9 |
# File 'lib/pitcher.rb', line 7 def team_abbrev @team_abbrev end |
#throws ⇒ Object
Returns the value of attribute throws.
8 9 10 |
# File 'lib/pitcher.rb', line 8 def throws @throws end |
#weight ⇒ Object
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_game ⇒ Object
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_pitches ⇒ Object
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_ab ⇒ Object
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 |