Sha256: 4ea5024cd6bbdcd5c926267b1b9f3a893fa70a3ed53e1096b9769d34a3a13189

Contents?: true

Size: 1014 Bytes

Versions: 108

Compression:

Stored size: 1014 Bytes

Contents

module Sportradar
  module Api
    class Nfl::DepthChart < Data
      include Enumerable
      attr_accessor :response, :chart

      def initialize(data)
        generate_chart(data)
      end

      def team(number)
        teams[number]
      end

      def each
        populate_teams
        teams.each { |team| yield team }
      end

      private

      def teams
        @teams ||= populate_teams
      end

      def populate_teams
        (1..3).each_with_object({}) do |i, hash|
          hash[i] = generate_team(i)
        end
      end

      def generate_team(number)
        @chart.each_with_object({}) do |(pos_name, groups), memo|
          memo[pos_name] = groups[number.to_s]
        end
      end

      def generate_chart(data)
        @chart = data['position'].each_with_object({}) do |position, memo|
          players = position['player'].map { |h| Sportradar::Api::Nfl::Player.new(h) }
          memo[position['name']] = players.group_by(&:depth)
        end
      end

    end
  end
end

Version data entries

108 entries across 108 versions & 1 rubygems

Version Path
sportradar-api-0.10.15 lib/sportradar/api/nfl/depth_chart.rb
sportradar-api-0.10.14 lib/sportradar/api/nfl/depth_chart.rb
sportradar-api-0.10.13 lib/sportradar/api/nfl/depth_chart.rb
sportradar-api-0.10.12 lib/sportradar/api/nfl/depth_chart.rb
sportradar-api-0.10.11 lib/sportradar/api/nfl/depth_chart.rb
sportradar-api-0.10.10 lib/sportradar/api/nfl/depth_chart.rb
sportradar-api-0.10.9 lib/sportradar/api/nfl/depth_chart.rb
sportradar-api-0.10.8 lib/sportradar/api/nfl/depth_chart.rb
sportradar-api-0.10.7 lib/sportradar/api/nfl/depth_chart.rb
sportradar-api-0.10.6 lib/sportradar/api/nfl/depth_chart.rb
sportradar-api-0.10.5 lib/sportradar/api/nfl/depth_chart.rb
sportradar-api-0.10.4 lib/sportradar/api/nfl/depth_chart.rb
sportradar-api-0.10.3 lib/sportradar/api/nfl/depth_chart.rb
sportradar-api-0.10.2 lib/sportradar/api/nfl/depth_chart.rb
sportradar-api-0.10.1 lib/sportradar/api/nfl/depth_chart.rb
sportradar-api-0.10.0 lib/sportradar/api/nfl/depth_chart.rb
sportradar-api-0.9.59 lib/sportradar/api/nfl/depth_chart.rb
sportradar-api-0.9.58 lib/sportradar/api/nfl/depth_chart.rb
sportradar-api-0.9.57 lib/sportradar/api/nfl/depth_chart.rb
sportradar-api-0.9.56 lib/sportradar/api/nfl/depth_chart.rb