Sha256: 28f88670e11c7fc928c72d8ffa29ec1c9a42192c5aebb3121d9c690073058dc8

Contents?: true

Size: 711 Bytes

Versions: 2

Compression:

Stored size: 711 Bytes

Contents

module SportsDataApi
  module Nhl
    class Season
      attr_reader :id, :year, :type

      def initialize(json)
        @json = json
        @id = json['season']['id']
        @year = json['season']['year']
        @type = json['season']['type'].to_sym
      end

      def games
        @games ||= json.fetch('games', []).map do |game_json|
          Game.new(year: year, season: type, json: game_json)
        end
      end

      ##
      # Check if the requested season is a valid
      # NHL season type.
      #
      # The only valid types are: :pre, :reg, :pst
      def self.valid?(season)
        %i[PRE REG PST].include?(season)
      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/season.rb
sports_data_api-0.15.2 lib/sports_data_api/nhl/season.rb