Sha256: 310859b87c99e9ed9b6164edcbf92be8820b66d6dcf2e68d14f3553aac9ba862

Contents?: true

Size: 661 Bytes

Versions: 5

Compression:

Stored size: 661 Bytes

Contents

module SportsDataApi
  module Nhl
    class Teams
      include Enumerable

      def initialize(json)
        @json = json
      end

      def teams
        @teams ||= json['conferences'].flat_map do |conference|
          conference['divisions'].flat_map do |division|
            division['teams'].map do |team_json|
              Team.new(team_json, conference['alias'], division['alias'])
            end
          end
        end
      end

      ##
      # Make the class Enumerable
      def each
        return teams.each unless block_given?
        teams.each { |team| yield team }
      end

      private

      attr_reader :json
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
sports_data_api-0.15.1 lib/sports_data_api/nhl/teams.rb
sports_data_api-0.15.0 lib/sports_data_api/nhl/teams.rb
sports_data_api-0.14.1 lib/sports_data_api/nhl/teams.rb
sports_data_api-0.14.0 lib/sports_data_api/nhl/teams.rb
sports_data_api-0.13.0 lib/sports_data_api/nhl/teams.rb