Class: NbaSchedule

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

Overview

Access NBA team schedule data

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from PrintUtils

#asTable

Methods included from NbaUrls

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

Constructor Details

#initialize(args) ⇒ NbaSchedule

Note:

Season Types: 1-Preseason; 2-Regular Season; 3-Playoffs

Read Schedule data for a given Team

Examples:

test     = NbaSchedule.new('', file: 'test/data/testData.html')
pre      = NbaSchedule.new('UTA', s_type: 1)
playoffs = NbaSchedule.new('GSW', s_type: 3)

Parameters:

  • team_id (String)

    Team ID

  • file (String)

    HTML Test Data

  • season_type (Integer)

    Season Type

  • year (Integer)

    Ending Year of Season



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/hoopscrape/NbaSchedule.rb', line 20

def initialize(args)
  doc, seasontype = getNokoDoc(args)
  return if doc.nil?

  @game_list = [] # Processed Schedule Data
  @next_game = 0  # Cursor to start of Future Games

  schedule, @year, indicator, tid = collectNodeSets(doc)
  season_valid = verifySeasonType(seasontype, indicator)
  seasontype   = findSeasonType(indicator) if seasontype.to_i.eql?(0)

  @wins = @losses = 0
  processSeason(schedule, tid, @year, seasontype, args[:format]) if season_valid && !seasontype.eql?(0)
  @allGames    = Navigator.new(@game_list)
  @futureGames = Navigator.new(@game_list[@next_game, game_list.size])
  @pastGames   = Navigator.new(@game_list[0, @next_game])
  @game_list   = nil
  @year = "#{@year}-#{(@year + 1).to_s[2, 4]}"
end

Instance Attribute Details

#allGamesNavigator (readonly)

Returns Navigator All Schedule data.

Returns:

  • (Navigator)

    Navigator All Schedule data

See Also:

  • GAME_F
  • GAME_P


43
44
45
# File 'lib/hoopscrape/NbaSchedule.rb', line 43

def allGames
  @allGames
end

#futureGamesNavigator (readonly)

Returns Navigator for Future Games.

Returns:

See Also:

  • SymbolDefaults::GAME_F


80
81
82
# File 'lib/hoopscrape/NbaSchedule.rb', line 80

def futureGames
  @futureGames
end

#game_listObject (readonly)

Returns the value of attribute game_list.



7
8
9
# File 'lib/hoopscrape/NbaSchedule.rb', line 7

def game_list
  @game_list
end

#lossesObject (readonly)

Returns the value of attribute losses.



7
8
9
# File 'lib/hoopscrape/NbaSchedule.rb', line 7

def losses
  @losses
end

#next_gameObject (readonly)

Returns the value of attribute next_game.



7
8
9
# File 'lib/hoopscrape/NbaSchedule.rb', line 7

def next_game
  @next_game
end

#pastGamesNavigator (readonly)

Return Schedule info of Past Games

Returns:

See Also:

  • SymbolDefaults::GAME_P


86
87
88
# File 'lib/hoopscrape/NbaSchedule.rb', line 86

def pastGames
  @pastGames
end

#winsObject (readonly)

Returns the value of attribute wins.



7
8
9
# File 'lib/hoopscrape/NbaSchedule.rb', line 7

def wins
  @wins
end

#yearObject (readonly)

Returns the value of attribute year.



7
8
9
# File 'lib/hoopscrape/NbaSchedule.rb', line 7

def year
  @year
end

Instance Method Details

#lastGameObject

Returns Schedule info of last completed game

Examples:

lastGame #=> ['UTA', '12', '00:00:00', 'false', 'Nov 20', 'false', 'DAL', 'false', '93', '102', '400828071', '6', '6', '2015-11-20 00:00:00', '2']

Returns:

  • (Object)

    Past Schedule Row (Array/Hash/Struct)

See Also:

  • SymbolDefaults::GAME_P


61
62
63
# File 'lib/hoopscrape/NbaSchedule.rb', line 61

def lastGame
  allGames[][@next_game - 1]
end

#nextGame[Object]

Returns Schedule info of next game

Examples:

nextGame #=> ['UTA', '13', 'Nov 23', 'true', 'OKC', '9:00 PM ET', 'false', '2015-11-23 21:00:00', '2']

Returns:

  • ([Object])

    Future Schedule Row (Array/Hash/Struct)

See Also:

  • GAME_F


51
52
53
# File 'lib/hoopscrape/NbaSchedule.rb', line 51

def nextGame
  allGames[][@next_game] unless allGames[].nil?
end

#nextGameIdInteger

Returns Game # of Next Game.

Returns:

  • (Integer)

    Game # of Next Game



66
67
68
# File 'lib/hoopscrape/NbaSchedule.rb', line 66

def nextGameId
  @next_game
end

#nextTeamIdString

Returns Team ID of next opponent.

Examples:

nextTeamId #=> "OKC"

Returns:

  • (String)

    Team ID of next opponent



73
74
75
# File 'lib/hoopscrape/NbaSchedule.rb', line 73

def nextTeamId
  nextGame[4] if nextGame
end