Class: NbaPlayer

Inherits:
Object
  • Object
show all
Includes:
NbaUrls
Defined in:
lib/espnscrape/NbaPlayer.rb

Overview

Read basic bio info from ESPN Player page

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#ageObject

Returns the value of attribute age.



4
5
6
# File 'lib/espnscrape/NbaPlayer.rb', line 4

def age
  @age
end

#collegeObject

Returns the value of attribute college.



4
5
6
# File 'lib/espnscrape/NbaPlayer.rb', line 4

def college
  @college
end

#h_ftObject

Returns the value of attribute h_ft.



4
5
6
# File 'lib/espnscrape/NbaPlayer.rb', line 4

def h_ft
  @h_ft
end

#h_inObject

Returns the value of attribute h_in.



4
5
6
# File 'lib/espnscrape/NbaPlayer.rb', line 4

def h_in
  @h_in
end

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/espnscrape/NbaPlayer.rb', line 4

def name
  @name
end

#positionObject

Returns the value of attribute position.



4
5
6
# File 'lib/espnscrape/NbaPlayer.rb', line 4

def position
  @position
end

#weightObject

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