Class: Sportradar::Api::Basketball::Nba::Series

Inherits:
Season
  • Object
show all
Defined in:
lib/sportradar/api/basketball/nba/series.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Data

#all_attributes, #attributes, #create_data, #parse_into_array, #parse_into_array_with_options, #parse_out_hashes, #structure_links, #update_data

Constructor Details

#initialize(data, **opts) ⇒ Series

Returns a new instance of Series.



9
10
11
12
13
14
15
16
17
18
# File 'lib/sportradar/api/basketball/nba/series.rb', line 9

def initialize(data, **opts)
  @response = data
  @api      = opts[:api]

  @id         = data['id']
  @games_hash = {}
  @participants_hash = {}

  update(data, **opts)
end

Instance Attribute Details

#idObject

Returns the value of attribute id.



6
7
8
# File 'lib/sportradar/api/basketball/nba/series.rb', line 6

def id
  @id
end

#responseObject

Returns the value of attribute response.



6
7
8
# File 'lib/sportradar/api/basketball/nba/series.rb', line 6

def response
  @response
end

#roundObject

Returns the value of attribute round.



6
7
8
# File 'lib/sportradar/api/basketball/nba/series.rb', line 6

def round
  @round
end

#start_dateObject

Returns the value of attribute start_date.



6
7
8
# File 'lib/sportradar/api/basketball/nba/series.rb', line 6

def start_date
  @start_date
end

#statusObject

Returns the value of attribute status.



6
7
8
# File 'lib/sportradar/api/basketball/nba/series.rb', line 6

def status
  @status
end

#titleObject Also known as: name

Returns the value of attribute title.



6
7
8
# File 'lib/sportradar/api/basketball/nba/series.rb', line 6

def title
  @title
end

Instance Method Details

#closed?Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/sportradar/api/basketball/nba/series.rb', line 65

def closed?
  'closed' == status
end

#completed?Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/sportradar/api/basketball/nba/series.rb', line 62

def completed?
  'complete' == status
end

#finished?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/sportradar/api/basketball/nba/series.rb', line 59

def finished?
  ['complete', 'closed'].include? status
end

#future?Boolean

status helpers

Returns:

  • (Boolean)


53
54
55
# File 'lib/sportradar/api/basketball/nba/series.rb', line 53

def future?
  ['scheduled', 'delayed', 'created', 'time-tbd'].include? status
end

#gamesObject



31
32
33
# File 'lib/sportradar/api/basketball/nba/series.rb', line 31

def games
  @games_hash.values
end

#participantsObject



39
40
41
# File 'lib/sportradar/api/basketball/nba/series.rb', line 39

def participants
  @participants_hash.values
end

#scheduledObject



48
49
50
# File 'lib/sportradar/api/basketball/nba/series.rb', line 48

def scheduled
  games.first&.scheduled
end

#started?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/sportradar/api/basketball/nba/series.rb', line 56

def started?
  ['inprogress', 'halftime', 'delayed'].include? status
end

#update(data, **opts) ⇒ Object



20
21
22
23
24
25
26
27
28
29
# File 'lib/sportradar/api/basketball/nba/series.rb', line 20

def update(data, **opts)
  @title      = data['title']       if data['title']
  @round      = data['round']       if data['round']
  @status     = data['status']      if data['status']
  @start_date = data['start_date']  if data['start_date']


  update_participants(data['participants']) if data['participants']
  update_games(data['games'])               if data['games']
end

#update_games(data) ⇒ Object



35
36
37
# File 'lib/sportradar/api/basketball/nba/series.rb', line 35

def update_games(data)
  create_data(@games_hash, data, klass: Game, api: @api, series: self)
end

#update_participants(data) ⇒ Object



43
44
45
46
# File 'lib/sportradar/api/basketball/nba/series.rb', line 43

def update_participants(data)
  data.map! { |hash| hash.merge!(hash.delete('team') || {}) }
  create_data(@participants_hash, data, klass: Team, api: @api, series: self)
end