class NbaPlayer
Read basic bio info from ESPN Player page
Attributes
age[RW]
@return [Integer] Age
college[RW]
@return [String] College
h_ft[RW]
@return [Integer] Height (ft)
h_in[RW]
@return [Integer] Height (in)
id[RW]
@return [Integer] id
name[RW]
@return [String] Name
position[RW]
@return [String] Position
weight[RW]
@return [Integer] Weight
Public Class Methods
new(espn_player_id, file = '')
click to toggle source
Read Player Data
# File lib/hoopscrape/NbaPlayer.rb, line 23 def initialize(espn_player_id, file = '') espn_player_id = espn_player_id.to_s if !espn_player_id.empty? url = playerUrl + espn_player_id doc = Nokogiri::HTML(open(url)) else doc = Nokogiri::HTML(open(file)) rescue nil end return if doc.nil? @id = espn_player_id.to_i readInfo(doc) end
Public Instance Methods
height_ft()
click to toggle source
alias for h_ft
# File lib/hoopscrape/NbaPlayer.rb, line 38 def height_ft @h_ft end
height_in()
click to toggle source
alias for h_in
# File lib/hoopscrape/NbaPlayer.rb, line 43 def height_in @h_in end
Private Instance Methods
gatherHeightWeight(d)
click to toggle source
# File lib/hoopscrape/NbaPlayer.rb, line 67 def gatherHeightWeight(d) h_w = d.xpath("//ul[@class='general-info']/li")[1] h_w.text.split(',') unless h_w.nil? end
processAge(d)
click to toggle source
# File lib/hoopscrape/NbaPlayer.rb, line 62 def processAge(d) /:\s(?<age_num>\d\d)/ =~ d.xpath('//span[text() = "Born"]/parent::li').text @age = age_num.to_i.to_s end
processHeight(height)
click to toggle source
# File lib/hoopscrape/NbaPlayer.rb, line 77 def processHeight(height) if !height.nil? && !height.empty? @h_ft, @h_in = height.strip.split('\'') @h_in = @h_in.delete('"').strip else @h_ft = @h_in = 0 end end
processWeight(weight)
click to toggle source
# File lib/hoopscrape/NbaPlayer.rb, line 72 def processWeight(weight) return 0 if weight.nil? || weight.empty? weight.strip.split(' ')[0] end
readInfo(d)
click to toggle source
Extract basic bio info info class attributes
# File lib/hoopscrape/NbaPlayer.rb, line 50 def readInfo(d) @name = d.xpath("//div[@class='mod-content']/*/h1 | //div[@class='mod-content']/h1")[0].text.strip @position = d.xpath("//ul[@class='general-info']/li")[0].text.gsub(/#\d*\s*/, '') @college = d.xpath('//span[text() = "College"]/parent::li').text.gsub('College', '') height, weight = gatherHeightWeight(d) @weight = processWeight(weight) processHeight(height) processAge(d) end