Class: HofStats::Player

Inherits:
Object
  • Object
show all
Defined in:
lib/hof_stats/player.rb

Constant Summary collapse

@@all =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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_avgObject

Returns the value of attribute batting_avg.



3
4
5
# File 'lib/hof_stats/player.rb', line 3

def batting_avg
  @batting_avg
end

#eraObject

Returns the value of attribute era.



3
4
5
# File 'lib/hof_stats/player.rb', line 3

def era
  @era
end

#gamesObject

Returns the value of attribute games.



3
4
5
# File 'lib/hof_stats/player.rb', line 3

def games
  @games
end

#hitsObject

Returns the value of attribute hits.



3
4
5
# File 'lib/hof_stats/player.rb', line 3

def hits
  @hits
end

#homersObject

Returns the value of attribute homers.



3
4
5
# File 'lib/hof_stats/player.rb', line 3

def homers
  @homers
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/hof_stats/player.rb', line 3

def name
  @name
end

#percentObject

Returns the value of attribute percent.



3
4
5
# File 'lib/hof_stats/player.rb', line 3

def percent
  @percent
end

#positionObject

Returns the value of attribute position.



3
4
5
# File 'lib/hof_stats/player.rb', line 3

def position
  @position
end

#runsObject

Returns the value of attribute runs.



3
4
5
# File 'lib/hof_stats/player.rb', line 3

def runs
  @runs
end

#strikeoutsObject

Returns the value of attribute strikeouts.



3
4
5
# File 'lib/hof_stats/player.rb', line 3

def strikeouts
  @strikeouts
end

#urlObject

Returns the value of attribute url.



3
4
5
# File 'lib/hof_stats/player.rb', line 3

def url
  @url
end

#votesObject

Returns the value of attribute votes.



3
4
5
# File 'lib/hof_stats/player.rb', line 3

def votes
  @votes
end

#wlpercentObject

Returns the value of attribute wlpercent.



3
4
5
# File 'lib/hof_stats/player.rb', line 3

def wlpercent
  @wlpercent
end

#yearObject

Returns the value of attribute year.



3
4
5
# File 'lib/hof_stats/player.rb', line 3

def year
  @year
end

Class Method Details

.allObject



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

#docObject



66
67
68
# File 'lib/hof_stats/player.rb', line 66

def doc
    @doc = Nokogiri::HTML(open(self.url))
end