Class: NbaPlayer
- Inherits:
-
Object
- Object
- NbaPlayer
- Includes:
- NbaUrls
- Defined in:
- lib/espnscrape/NbaPlayer.rb
Overview
Read basic bio info from ESPN Player page
Instance Attribute Summary collapse
-
#age ⇒ Object
Returns the value of attribute age.
-
#college ⇒ Object
Returns the value of attribute college.
-
#h_ft ⇒ Object
Returns the value of attribute h_ft.
-
#h_in ⇒ Object
Returns the value of attribute h_in.
-
#name ⇒ Object
Returns the value of attribute name.
-
#position ⇒ Object
Returns the value of attribute position.
-
#weight ⇒ Object
Returns the value of attribute weight.
Instance Method Summary collapse
-
#initialize(espn_player_id) ⇒ NbaPlayer
constructor
A new instance of NbaPlayer.
-
#readInfo(d) ⇒ Object
Extract basic bio info info class attributes.
Methods included from NbaUrls
#boxScoreUrl, #formatTeamUrl, #getTid, #playerUrl, #teamListUrl, #teamRosterUrl, #teamScheduleUrl
Constructor Details
#initialize(espn_player_id) ⇒ NbaPlayer
Returns a new instance of NbaPlayer.
6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/espnscrape/NbaPlayer.rb', line 6 def initialize(espn_player_id) espn_player_id = espn_player_id.to_s unless (espn_player_id.empty?) url = playerUrl + espn_player_id doc = Nokogiri::HTML(open(url)) if doc.nil? puts "URL Unreachable: " + url exit 1 end end readInfo(doc) end |
Instance Attribute Details
#age ⇒ Object
Returns the value of attribute age.
4 5 6 |
# File 'lib/espnscrape/NbaPlayer.rb', line 4 def age @age end |
#college ⇒ Object
Returns the value of attribute college.
4 5 6 |
# File 'lib/espnscrape/NbaPlayer.rb', line 4 def college @college end |
#h_ft ⇒ Object
Returns the value of attribute h_ft.
4 5 6 |
# File 'lib/espnscrape/NbaPlayer.rb', line 4 def h_ft @h_ft end |
#h_in ⇒ Object
Returns the value of attribute h_in.
4 5 6 |
# File 'lib/espnscrape/NbaPlayer.rb', line 4 def h_in @h_in end |
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/espnscrape/NbaPlayer.rb', line 4 def name @name end |
#position ⇒ Object
Returns the value of attribute position.
4 5 6 |
# File 'lib/espnscrape/NbaPlayer.rb', line 4 def position @position end |
#weight ⇒ Object
Returns the value of attribute weight.
4 5 6 |
# File 'lib/espnscrape/NbaPlayer.rb', line 4 def weight @weight end |
Instance Method Details
#readInfo(d) ⇒ Object
Extract basic bio info info class attributes
21 22 23 24 25 26 27 28 29 |
# File 'lib/espnscrape/NbaPlayer.rb', line 21 def readInfo(d) @name = d.xpath("//div[@class='mod-content']/h1")[0].text.strip @position = d.xpath("//ul[@class='general-info']/li")[0].text.strip @college = d.xpath('//ul[contains(@class,"player-metadata")]/li')[2].text.gsub('College','') height, weight = d.xpath("//ul[@class='general-info']/li")[1].text.split(',') @weight = weight.strip.split(' ')[0] @h_ft, @h_in = height.strip.split('\'') @h_in = @h_in.gsub('"','').strip end |