Class: NbaTeamList

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

Overview

Access list of NBA teams

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 = {}) ⇒ [String]

Scrape Team Data



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/espnscrape/NbaTeamList.rb', line 15

def initialize(args = {})
  doc = args[:file] ? Nokogiri::HTML(open(args[:file])) : Nokogiri::HTML(open(teamListUrl))
  return if doc.nil?

  # Collect
  @header = doc.xpath('//h2')[0].text.strip # Table Header
  team_names = doc.xpath('//h5/a/text()')   # Team Names

  @teamList = []
  h = 0 # Head of teamNames range
  west_conf = %w(Northwest Pacific Southwest) # Western Conference Divs
  # Process Teams by Division
  divs = %w(Atlantic Pacific Central Southwest Southeast Northwest)
  divs.each do |div|
    @teamList += processTeams(div, team_names[h, 5], west_conf) # Store Team Data
    h += 5
  end
  # puts "Converting to #{args[:format]}"
  @teamList = @teamList.send(args[:format], S_TEAM) if args[:format]
  @teamList = Navigator.new(@teamList)
end

Instance Attribute Details

#headerString

Returns Table Title.

Returns:



7
8
9
# File 'lib/espnscrape/NbaTeamList.rb', line 7

def header
  @header
end

#teamList[[String]]

Returns Table of NBA Teams.

Returns:

  • ([[String]])

    Table of NBA Teams



11
12
13
# File 'lib/espnscrape/NbaTeamList.rb', line 11

def teamList
  @teamList
end