module NbaUrls
Methods and Urls to access ESPN NBA data
Public Instance Methods
adjustTeamName(team_name)
click to toggle source
Adjust Team Names
# File lib/hoopscrape/NbaUrls.rb, line 82 def adjustTeamName(team_name) special = { 'LA Clippers' => 'Los Angeles Clippers' } special.keys.include?(team_name) ? special[team_name] : team_name end
boxScoreUrl()
click to toggle source
@return [String] URL to access Boxscore
# File lib/hoopscrape/NbaUrls.rb, line 4 def boxScoreUrl 'http://scores.espn.go.com/nba/boxscore?gameId=' end
checkSpecial(abbr)
click to toggle source
Adjust Outlier Abbreviations
# File lib/hoopscrape/NbaUrls.rb, line 75 def checkSpecial(abbr) abbr.upcase! special = { 'OCT' => 'OKC', 'PTB' => 'POR', 'BRO' => 'BKN', 'LA' => 'LAC' } special.keys.include?(abbr) ? special[abbr] : abbr end
formatTeamUrl(team_id, url)
click to toggle source
Generate team specific URL @param team_id [String] Team ID @param url [String] URL String
@return [String] Formatted URL @example
NbaUrls.formatTeamUrl('uta', NbaUrls.teamRosterUrl) #=> "http://espn.go.com/nba/team/roster/_/name/utah/"
# File lib/hoopscrape/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)
click to toggle source
Derive three letter Team ID from Team Name @param team_name [String] Full Team Name @return [String] Team ID @example
getTid("Oklahoma City Thunder") #=> "OKC"
# File lib/hoopscrape/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
playerUrl()
click to toggle source
@return [String] URL to access Player profile
# File lib/hoopscrape/NbaUrls.rb, line 27 def playerUrl 'http://espn.go.com/nba/player/_/id/' end
seasonYearEnd(date = nil)
click to toggle source
# File lib/hoopscrape/NbaUrls.rb, line 41 def seasonYearEnd(date = nil) return seasonYears(date).split('-')[1] rescue nil end
seasonYears(date = nil)
click to toggle source
@return [String] Season Years @example
seasonYears('2015-07-10') => '2015-2016'
# File lib/hoopscrape/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
teamListUrl()
click to toggle source
@return [String] URL to access NBA Team List
# File lib/hoopscrape/NbaUrls.rb, line 9 def teamListUrl 'http://espn.go.com/nba/teams' end
teamRosterUrl()
click to toggle source
@return [String] URL to access Team Roster
# File lib/hoopscrape/NbaUrls.rb, line 22 def teamRosterUrl 'http://espn.go.com/nba/team/roster/_/name/%s/' end
teamScheduleUrl(seasontype = nil, year = nil)
click to toggle source
@param seasontype [INT] 1-Pre 2-Regular 3-Playoff @return [String] URL to access Team Schedule
# File lib/hoopscrape/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