Sha256: 3b09c0a56bd9b59841e54d21facd03e931dfba60482ed65e17aa2244c3de6cdc

Contents?: true

Size: 720 Bytes

Versions: 2

Compression:

Stored size: 720 Bytes

Contents

require 'forwardable'

module SportsDataApi
  module Nfl
    class Teams
      extend Forwardable
      include Enumerable

      def_delegators :teams, :each

      def initialize(json)
        @json = json
      end

      def teams
        @teams ||= json.fetch('conferences', []).flat_map do |conference_json|
          conference = conference_json['name']
          conference_json['divisions'].flat_map do |division_json|
            division = division_json['name']
            division_json['teams'].flat_map do |team_json|
              Team.new(team_json, conference: conference, division: division)
            end
          end
        end
      end

      private

      attr_reader :json
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sports_data_api-0.15.3 lib/sports_data_api/nfl/teams.rb
sports_data_api-0.15.2 lib/sports_data_api/nfl/teams.rb