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
-
#boxScoreUrl ⇒ String
URL to access Boxscore.
-
#checkSpecial(abbr) ⇒ Object
Adjust Outlier Abbreviations.
-
#formatTeamUrl(team_id, url) ⇒ String
Generate team specific URL.
-
#getTid(team_name) ⇒ String
Derive three letter Team ID from Team Name.
-
#playerUrl ⇒ String
URL to access Player profile.
- #seasonYearEnd(date = nil) ⇒ Object
-
#seasonYears(date = nil) ⇒ String
Season Years.
-
#teamListUrl ⇒ String
URL to access NBA Team List.
-
#teamRosterUrl ⇒ String
URL to access Team Roster.
-
#teamScheduleUrl(seasontype = nil, year = nil) ⇒ String
URL to access Team Schedule.
Instance Method Details
#boxScoreUrl ⇒ String
Returns 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
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
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 |
#playerUrl ⇒ String
Returns 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.
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 |
#teamListUrl ⇒ String
Returns 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 |
#teamRosterUrl ⇒ String
Returns 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.
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 |