Class: HofStats::Player
- Inherits:
-
Object
- Object
- HofStats::Player
- Defined in:
- lib/hof_stats/player.rb
Constant Summary collapse
- @@all =
[]
Instance Attribute Summary collapse
-
#batting_avg ⇒ Object
Returns the value of attribute batting_avg.
-
#era ⇒ Object
Returns the value of attribute era.
-
#games ⇒ Object
Returns the value of attribute games.
-
#hits ⇒ Object
Returns the value of attribute hits.
-
#homers ⇒ Object
Returns the value of attribute homers.
-
#name ⇒ Object
Returns the value of attribute name.
-
#percent ⇒ Object
Returns the value of attribute percent.
-
#position ⇒ Object
Returns the value of attribute position.
-
#runs ⇒ Object
Returns the value of attribute runs.
-
#strikeouts ⇒ Object
Returns the value of attribute strikeouts.
-
#url ⇒ Object
Returns the value of attribute url.
-
#votes ⇒ Object
Returns the value of attribute votes.
-
#wlpercent ⇒ Object
Returns the value of attribute wlpercent.
-
#year ⇒ Object
Returns the value of attribute year.
Class Method Summary collapse
Instance Method Summary collapse
- #doc ⇒ Object
-
#initialize(name = nil, year = nil, votes = nil, percent = nil, url = nil) ⇒ Player
constructor
A new instance of Player.
Constructor Details
#initialize(name = nil, year = nil, votes = nil, percent = nil, url = nil) ⇒ Player
Returns a new instance of Player.
17 18 19 20 21 22 23 24 |
# 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 |
Instance Attribute Details
#batting_avg ⇒ Object
Returns the value of attribute batting_avg.
3 4 5 |
# File 'lib/hof_stats/player.rb', line 3 def batting_avg @batting_avg end |
#era ⇒ Object
Returns the value of attribute era.
3 4 5 |
# File 'lib/hof_stats/player.rb', line 3 def era @era end |
#games ⇒ Object
Returns the value of attribute games.
3 4 5 |
# File 'lib/hof_stats/player.rb', line 3 def games @games end |
#hits ⇒ Object
Returns the value of attribute hits.
3 4 5 |
# File 'lib/hof_stats/player.rb', line 3 def hits @hits end |
#homers ⇒ Object
Returns the value of attribute homers.
3 4 5 |
# File 'lib/hof_stats/player.rb', line 3 def homers @homers end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/hof_stats/player.rb', line 3 def name @name end |
#percent ⇒ Object
Returns the value of attribute percent.
3 4 5 |
# File 'lib/hof_stats/player.rb', line 3 def percent @percent end |
#position ⇒ Object
Returns the value of attribute position.
3 4 5 |
# File 'lib/hof_stats/player.rb', line 3 def position @position end |
#runs ⇒ Object
Returns the value of attribute runs.
3 4 5 |
# File 'lib/hof_stats/player.rb', line 3 def runs @runs end |
#strikeouts ⇒ Object
Returns the value of attribute strikeouts.
3 4 5 |
# File 'lib/hof_stats/player.rb', line 3 def strikeouts @strikeouts end |
#url ⇒ Object
Returns the value of attribute url.
3 4 5 |
# File 'lib/hof_stats/player.rb', line 3 def url @url end |
#votes ⇒ Object
Returns the value of attribute votes.
3 4 5 |
# File 'lib/hof_stats/player.rb', line 3 def votes @votes end |
#wlpercent ⇒ Object
Returns the value of attribute wlpercent.
3 4 5 |
# File 'lib/hof_stats/player.rb', line 3 def wlpercent @wlpercent end |
#year ⇒ Object
Returns the value of attribute year.
3 4 5 |
# File 'lib/hof_stats/player.rb', line 3 def year @year end |
Class Method Details
.all ⇒ Object
26 27 28 |
# File 'lib/hof_stats/player.rb', line 26 def self.all @@all end |
.new_from_index(p) ⇒ Object
7 8 9 10 11 12 13 14 15 |
# 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 |
Instance Method Details
#doc ⇒ Object
66 67 68 |
# File 'lib/hof_stats/player.rb', line 66 def doc @doc = Nokogiri::HTML(open(self.url)) end |