Sha256: add9b6a8f5821728605a9bb3fcf3540836291c0512f17f951cc6cfca55aec6a4

Contents?: true

Size: 905 Bytes

Versions: 4

Compression:

Stored size: 905 Bytes

Contents

module Sportradar
  module Api
    class Nfl::LeagueDepthChart < Data
      include Enumerable
      attr_accessor :response, :season, :charts

      def initialize(data)
        @response = data
        depth_chart_data = data["season"]['depth_charts']
        @season = Sportradar::Api::Nfl::Season.new data["season"] if data["season"]
        # @teams = depth_chart_data["team"].map {|team| Sportradar::Api::Nfl::Team.new team } if depth_chart_data["team"]
        @charts = depth_chart_data["team"].map {|team| Sportradar::Api::Nfl::TeamDepthChart.new(team, season) } if depth_chart_data["team"]
      end

      # id is preferred search, but we allow for team abbreviation too
      def team(id = nil, abbrev: nil)
        @charts.detect { |chart| chart.team_id == id || chart.abbrev == abbrev }
      end

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

    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
sportradar-api-0.9.3 lib/sportradar/api/nfl/league_depth_chart.rb
sportradar-api-0.9.2 lib/sportradar/api/nfl/league_depth_chart.rb
sportradar-api-0.9.1 lib/sportradar/api/nfl/league_depth_chart.rb
sportradar-api-0.9.0 lib/sportradar/api/nfl/league_depth_chart.rb