Module: NbaUrls

Included in:
NbaBoxScore, NbaPlayer, NbaRoster, NbaSchedule, NbaTeamList
Defined in:
lib/espnscrape/NbaUrls.rb

Overview

Methods and Urls to access ESPN NBA data

Instance Method Summary collapse

Instance Method Details

#boxScoreUrlString

Returns URL to access Boxscore.

Returns:

  • (String)

    URL to access Boxscore



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

def boxScoreUrl
  'http://scores.espn.go.com/nba/boxscore?gameId='
end

#checkSpecial(abbr) ⇒ Object

Adjust Outlier Abbreviations



75
76
77
78
79
# File 'lib/espnscrape/NbaUrls.rb', line 75

def checkSpecial(abbr)
  abbr.upcase!
  special = { 'OCT' => 'OKC', 'PTB' => 'POR', 'BRO' => 'BKN' }
  special.keys.include?(abbr) ? special[abbr] : abbr
end

#formatTeamUrl(team_id, url) ⇒ String

Generate team specific URL

Examples:

NbaUrls.formatTeamUrl('uta', NbaUrls.teamRosterUrl) #=> "http://espn.go.com/nba/team/roster/_/name/utah/"

Parameters:

Returns:



51
52
53
54
55
56
57
58
59
# File 'lib/espnscrape/NbaUrls.rb', line 51

def formatTeamUrl(team_id, url)
  team_id = team_id.downcase
  special = {
    'was' => 'wsh',	'nop' => 'no', 'sas' => 'sa', 'uta' => 'utah',
    'pho' => 'phx', 'gsw' => 'gs', 'nyk' => 'ny'
  }
  team_id = special[team_id] if special.keys.include?(team_id)
  url % [team_id]
end

#getTid(team_name) ⇒ String

Derive three letter Team ID from Team Name

Examples:

getTid("Oklahoma City Thunder") #=> "OKC"

Parameters:

  • team_name (String)

    Full Team Name

Returns:



67
68
69
70
71
72
# File 'lib/espnscrape/NbaUrls.rb', line 67

def getTid(team_name)
  result = ''
  words = team_name.split
  words.size > 2 ? words.each { |word| result << word[0] } : result = words[0][0, 3]
  checkSpecial(result)
end

#playerUrlString

Returns URL to access Player profile.

Returns:

  • (String)

    URL to access Player profile



27
28
29
# File 'lib/espnscrape/NbaUrls.rb', line 27

def playerUrl
  'http://espn.go.com/nba/player/_/id/'
end

#seasonYearEnd(date = nil) ⇒ Object



41
42
43
# File 'lib/espnscrape/NbaUrls.rb', line 41

def seasonYearEnd(date = nil)
  return seasonYears(date).split('-')[1] rescue nil
end

#seasonYears(date = nil) ⇒ String

Returns Season Years.

Examples:

seasonYears('2015-07-10') => '2015-2016'

Returns:



34
35
36
37
38
39
# File 'lib/espnscrape/NbaUrls.rb', line 34

def seasonYears(date = nil)
  return seasonYears(Date.today) if date.nil?
  date = Date.parse(date.to_s)
  return "#{date.year - 1}-#{date.year}" if date.month < 7
  "#{date.year}-#{date.year + 1}"
end

#teamListUrlString

Returns URL to access NBA Team List.

Returns:

  • (String)

    URL to access NBA Team List



9
10
11
# File 'lib/espnscrape/NbaUrls.rb', line 9

def teamListUrl
  'http://espn.go.com/nba/teams'
end

#teamRosterUrlString

Returns URL to access Team Roster.

Returns:

  • (String)

    URL to access Team Roster



22
23
24
# File 'lib/espnscrape/NbaUrls.rb', line 22

def teamRosterUrl
  'http://espn.go.com/nba/team/roster/_/name/%s/'
end

#teamScheduleUrl(seasontype = nil, year = nil) ⇒ String

Returns URL to access Team Schedule.

Parameters:

  • seasontype (INT) (defaults to: nil)

    1-Pre 2-Regular 3-Playoff

Returns:

  • (String)

    URL to access Team Schedule



15
16
17
18
19
# File 'lib/espnscrape/NbaUrls.rb', line 15

def teamScheduleUrl(seasontype = nil, year = nil)
  year ||= seasonYearEnd # Default to the current season
  seasontype ||= 3       # Default to playoff data
  "http://espn.go.com/nba/team/schedule/_/name/%s/year/#{year}/seasontype/#{seasontype}"
end