Class: NbaRoster

Inherits:
Object
  • Object
show all
Includes:
NbaUrls, PrintUtils
Defined in:
lib/espnscrape/NbaRoster.rb

Overview

Access NBA roster data

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from PrintUtils

#asTable

Methods included from NbaUrls

#boxScoreUrl, #checkSpecial, #formatTeamUrl, #getTid, #playerUrl, #seasonYearEnd, #seasonYears, #teamListUrl, #teamRosterUrl, #teamScheduleUrl

Constructor Details

#initialize(args = {}) ⇒ NbaRoster

Scrape Roster Data

Examples:

r = NbaRoster.new("UTA")
r = NbaRoster.new('', 'test/data/rosterData.html')


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/espnscrape/NbaRoster.rb', line 20

def initialize(args = {})
  if args[:team_id]
    url = formatTeamUrl(args[:team_id], teamRosterUrl) # Generate URL
    doc = Nokogiri::HTML(open(url)) # Get DOM
  elsif args[:file]
    doc = Nokogiri::HTML(open(args[:file]))
  end
  return if doc.nil?

  team_id ||= getTid(doc.title.split(/\d{4}/).first.strip)
  list      = doc.xpath('//div/div/table/tr')
  p_list    = list[2, list.length - 3] # Get Player Nodes

  @coach   = list[-1].children.first.text.split(':').last.strip # Read Coach Name
  @players = Navigator.new processPlayerTable(p_list, team_id, args[:format])
end

Instance Attribute Details

#coachString (readonly)



8
9
10
# File 'lib/espnscrape/NbaRoster.rb', line 8

def coach
  @coach
end

#players[[String]] (readonly)

Returns Team Roster

See Also:

  • ROSTER


13
14
15
# File 'lib/espnscrape/NbaRoster.rb', line 13

def players
  @players
end