Class: SportsDataApi::Nhl::Team

Inherits:
Object
  • Object
show all
Defined in:
lib/sports_data_api/nhl/team.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(json, conference = nil, division = nil) ⇒ Team

Returns a new instance of Team.



6
7
8
9
10
11
12
13
14
# File 'lib/sports_data_api/nhl/team.rb', line 6

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

Instance Attribute Details

#aliasObject (readonly)

Returns the value of attribute alias.



4
5
6
# File 'lib/sports_data_api/nhl/team.rb', line 4

def alias
  @alias
end

#idObject (readonly)

Returns the value of attribute id.



4
5
6
# File 'lib/sports_data_api/nhl/team.rb', line 4

def id
  @id
end

#marketObject (readonly)

Returns the value of attribute market.



4
5
6
# File 'lib/sports_data_api/nhl/team.rb', line 4

def market
  @market
end

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/sports_data_api/nhl/team.rb', line 4

def name
  @name
end

Instance Method Details

#==(other) ⇒ Object

Compare the Team with another team



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/sports_data_api/nhl/team.rb', line 43

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

#conferenceObject



16
17
18
# File 'lib/sports_data_api/nhl/team.rb', line 16

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

#divisionObject



20
21
22
# File 'lib/sports_data_api/nhl/team.rb', line 20

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

#playersObject



29
30
31
32
33
34
# File 'lib/sports_data_api/nhl/team.rb', line 29

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

#pointsObject



24
25
26
27
# File 'lib/sports_data_api/nhl/team.rb', line 24

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

#venueObject



36
37
38
39
# File 'lib/sports_data_api/nhl/team.rb', line 36

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