Sha256: 6de1b12d779ae19bf1525218678194fb234ccc5c456f78af1ef3e90b5268c12b

Contents?: true

Size: 671 Bytes

Versions: 2

Compression:

Stored size: 671 Bytes

Contents

module SportsDataApi
  module Nhl
    class Teams
      include Enumerable

      def initialize(json)
        @json = json
      end

      def teams
        @teams ||= json.fetch('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

2 entries across 2 versions & 1 rubygems

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