Class: Sportradar::Api::Football::Nfl::LeagueDepthChart

Inherits:
Data
  • Object
show all
Includes:
Enumerable
Defined in:
lib/sportradar/api/football/nfl/league_depth_chart.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) ⇒ LeagueDepthChart

Returns a new instance of LeagueDepthChart.



9
10
11
12
13
14
# File 'lib/sportradar/api/football/nfl/league_depth_chart.rb', line 9

def initialize(data, **opts)
  @response = data
  @charts_hash = {}

  update(data, **opts)
end

Instance Attribute Details

#chartsObject

Returns the value of attribute charts.



7
8
9
# File 'lib/sportradar/api/football/nfl/league_depth_chart.rb', line 7

def charts
  @charts
end

#responseObject

Returns the value of attribute response.



7
8
9
# File 'lib/sportradar/api/football/nfl/league_depth_chart.rb', line 7

def response
  @response
end

#week_numberObject

Returns the value of attribute week_number.



7
8
9
# File 'lib/sportradar/api/football/nfl/league_depth_chart.rb', line 7

def week_number
  @week_number
end

Instance Method Details

#eachObject



33
34
35
# File 'lib/sportradar/api/football/nfl/league_depth_chart.rb', line 33

def each
  self.charts.each { |chart| yield chart }
end

#team(id = nil, abbrev: nil) ⇒ Object

id is preferred search, but we allow for team abbreviation too



29
30
31
# File 'lib/sportradar/api/football/nfl/league_depth_chart.rb', line 29

def team(id = nil, abbrev: nil)
  charts.detect { |chart| chart.team_id == id || chart.abbrev == abbrev }
end

#update(data, **opts) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/sportradar/api/football/nfl/league_depth_chart.rb', line 16

def update(data, **opts)
  @week = data['week']
  @week_number = data.dig('week', 'sequence')
  create_data(@charts_hash, data["teams"], klass: TeamDepthChart, api: opts[:api])

  self
end