Class: Batter

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

Overview

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

Instance Attribute Summary collapse

Attributes inherited from Player

#appearances, #avg, #bat_order, #boxname, #era, #first, #game_position, #games, #gid, #hr, #last, #losses, #num, #position, #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/batter.rb', line 8

def bats
  @bats
end

#career_statsObject

Returns the value of attribute career_stats.



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

def career_stats
  @career_stats
end

#dobObject

Returns the value of attribute dob.



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

def dob
  @dob
end

#empty_statsObject

Returns the value of attribute empty_stats.



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

def empty_stats
  @empty_stats
end

#first_nameObject

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



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

def first_name
  @first_name
end

#heightObject

Returns the value of attribute height.



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

def height
  @height
end

#jersey_numberObject

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



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

def jersey_number
  @jersey_number
end

#last_nameObject

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



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

def last_name
  @last_name
end

#loaded_statsObject

Returns the value of attribute loaded_stats.



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

def loaded_stats
  @loaded_stats
end

#men_on_statsObject

Returns the value of attribute men_on_stats.



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

def men_on_stats
  @men_on_stats
end

#month_statsObject

Returns the value of attribute month_stats.



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

def month_stats
  @month_stats
end

#pidObject

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



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

def pid
  @pid
end

#posObject

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



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

def pos
  @pos
end

#risp_statsObject

Returns the value of attribute risp_stats.



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

def risp_stats
  @risp_stats
end

#season_statsObject

Returns the value of attribute season_stats.



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

def season_stats
  @season_stats
end

#team_abbrevObject

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



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

def team_abbrev
  @team_abbrev
end

#throwsObject

Returns the value of attribute throws.



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

def throws
  @throws
end

#vs_lhp_statsObject

Returns the value of attribute vs_lhp_stats.



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

def vs_lhp_stats
  @vs_lhp_stats
end

#vs_rhp_statsObject

Returns the value of attribute vs_rhp_stats.



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

def vs_rhp_stats
  @vs_rhp_stats
end

#weightObject

Returns the value of attribute weight.



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

def weight
  @weight
end

Class Method Details

.get_all_ids_for_game(gid) ⇒ Object

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



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/batter.rb', line 48

def self.get_all_ids_for_game(gid)
  batters_page = GamedayFetcher.fetch_batters_page(gid)
  results = []
  if batters_page
    doc = Hpricot(batters_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 batter
          str = link.inner_html
          str.strip!
          batter_id = str[0..str.length-5]
          results << batter_id
        end
      end
    end
  end
  results
end

Instance Method Details

#get_multihit_appearances(year) ⇒ Object

Returns an array of all the appearances (Batting) made by this player for the season specified, in which the player had more than 1 hit.



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/batter.rb', line 33

def get_multihit_appearances(year)
  appearances = get_all_appearances(year)
  mh_appearances = []
  # now go through all appearances to find those for this player
  appearances.each do |appearance|
    if appearance.h.to_i > 1 #add only multihit games
     mh_appearances << appearance
    end
  end
  mh_appearances
end

#load_from_id(gid, pid) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/batter.rb', line 13

def load_from_id(gid, pid)
  @gid = gid
  @pid = pid
  @xml_data = GamedayFetcher.fetch_batter(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_batting_stats
end