class HofStats::Player

Attributes

batting_avg[RW]
era[RW]
games[RW]
hits[RW]
homers[RW]
name[RW]
percent[RW]
position[RW]
runs[RW]
strikeouts[RW]
url[RW]
votes[RW]
wlpercent[RW]
year[RW]

Public Class Methods

all() click to toggle source
# File lib/hof_stats/player.rb, line 26
def self.all
    @@all
end
new(name=nil, year=nil, votes=nil, percent=nil, url=nil) click to toggle source
# File lib/hof_stats/player.rb, line 17
def initialize(name=nil, year=nil, votes=nil, percent=nil, url=nil)
    @name = name
    @year = year
    @votes = votes
    @percent = percent
    @url = url
    @@all << self
end
new_from_index(p) click to toggle source
# File lib/hof_stats/player.rb, line 7
def self.new_from_index(p)
    self.new(
        p.css("td[data-stat='player']").text,
        p.css("th[data-stat='year_ID']").text,
        p.css("td[data-stat='votes']").text,
        p.css("td[data-stat='votes_pct']").text,
        "https://baseball-reference.com#{p.css("td a").attribute("href").text}"
        )
end

Public Instance Methods

doc() click to toggle source
# File lib/hof_stats/player.rb, line 66
def doc
    @doc = Nokogiri::HTML(open(self.url))
end