Sha256: 51716a2639ccb5d9ecda20f735f3b3395dd8968820a3e6f342f6670c8cf73c4f

Contents?: true

Size: 1.23 KB

Versions: 108

Compression:

Stored size: 1.23 KB

Contents

module Sportradar
  module Api
    module Football
      class Nfl
        class 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]
            end
          end

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

        end
      end
    end
  end
end

Version data entries

108 entries across 108 versions & 1 rubygems

Version Path
sportradar-api-0.20.2 lib/sportradar/api/football/nfl/depth_chart.rb
sportradar-api-0.20.1 lib/sportradar/api/football/nfl/depth_chart.rb
sportradar-api-0.20.0 lib/sportradar/api/football/nfl/depth_chart.rb
sportradar-api-0.20.0.pre2 lib/sportradar/api/football/nfl/depth_chart.rb
sportradar-api-0.20.0.pre lib/sportradar/api/football/nfl/depth_chart.rb
sportradar-api-0.19.6 lib/sportradar/api/football/nfl/depth_chart.rb
sportradar-api-0.19.5 lib/sportradar/api/football/nfl/depth_chart.rb
sportradar-api-0.19.4 lib/sportradar/api/football/nfl/depth_chart.rb
sportradar-api-0.19.3 lib/sportradar/api/football/nfl/depth_chart.rb
sportradar-api-0.19.2 lib/sportradar/api/football/nfl/depth_chart.rb
sportradar-api-0.19.1 lib/sportradar/api/football/nfl/depth_chart.rb
sportradar-api-0.19.0 lib/sportradar/api/football/nfl/depth_chart.rb
sportradar-api-0.18.1 lib/sportradar/api/football/nfl/depth_chart.rb
sportradar-api-0.18.0 lib/sportradar/api/football/nfl/depth_chart.rb
sportradar-api-0.17.6 lib/sportradar/api/football/nfl/depth_chart.rb
sportradar-api-0.17.5 lib/sportradar/api/football/nfl/depth_chart.rb
sportradar-api-0.17.5.pre lib/sportradar/api/football/nfl/depth_chart.rb
sportradar-api-0.17.4 lib/sportradar/api/football/nfl/depth_chart.rb
sportradar-api-0.17.3 lib/sportradar/api/football/nfl/depth_chart.rb
sportradar-api-0.17.2 lib/sportradar/api/football/nfl/depth_chart.rb