Sha256: 8534905d5490c57e79918cd7bff31230f33cb3dd5d3a1cd21f4ba9ffea2ecfe1

Contents?: true

Size: 1.27 KB

Versions: 7

Compression:

Stored size: 1.27 KB

Contents

module SportsDataApi
  module Nhl
    class Team
      attr_reader :id, :name, :market, :alias

      def initialize(json, conference = nil, division = nil)
        @json = json
        @id = json['id']
        @name = json['name']
        @market = json['market']
        @alias = json['alias']
        @conference = conference
        @division = division
      end

      def conference
        @conference ||= json.fetch('conference', {})['alias']
      end

      def division
        @division ||= json.fetch('division', {})['alias']
      end

      def points
        return unless json['points']
        json['points'].to_i
      end

      def players
        return [] if json['players'].nil?
        @players ||= json['players'].map do |player_json|
          Player.new(player_json)
        end
      end

      def venue
        return if json['venue'].nil?
        @venue ||= Venue.new(json['venue'])
      end

      ##
      # Compare the Team with another team
      def ==(other)
        return false if id.nil?

        if other.is_a? SportsDataApi::Nhl::Team
          other.id && id === other.id
        elsif other.is_a? Symbol
          id.to_sym === other
        else
          super(other)
        end
      end

      private

      attr_reader :json
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
sports_data_api-0.15.3 lib/sports_data_api/nhl/team.rb
sports_data_api-0.15.2 lib/sports_data_api/nhl/team.rb
sports_data_api-0.15.1 lib/sports_data_api/nhl/team.rb
sports_data_api-0.15.0 lib/sports_data_api/nhl/team.rb
sports_data_api-0.14.1 lib/sports_data_api/nhl/team.rb
sports_data_api-0.14.0 lib/sports_data_api/nhl/team.rb
sports_data_api-0.13.0 lib/sports_data_api/nhl/team.rb