Class: NBA::Team

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#championshipsObject (readonly)

Returns the value of attribute championships.



3
4
5
# File 'lib/nba/team.rb', line 3

def championships
  @championships
end

#conferenceObject (readonly)

Returns the value of attribute conference.



3
4
5
# File 'lib/nba/team.rb', line 3

def conference
  @conference
end

#divisionObject (readonly)

Returns the value of attribute division.



3
4
5
# File 'lib/nba/team.rb', line 3

def division
  @division
end

#foundedObject (readonly)

Returns the value of attribute founded.



3
4
5
# File 'lib/nba/team.rb', line 3

def founded
  @founded
end

#head_coachObject (readonly) Also known as: coach

Returns the value of attribute head_coach.



3
4
5
# File 'lib/nba/team.rb', line 3

def head_coach
  @head_coach
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/nba/team.rb', line 3

def name
  @name
end

#playersObject (readonly)

Returns the value of attribute players.



3
4
5
# File 'lib/nba/team.rb', line 3

def players
  @players
end

#team_statsObject (readonly)

Returns the value of attribute team_stats.



3
4
5
# File 'lib/nba/team.rb', line 3

def team_stats
  @team_stats
end

Class Method Details

.allObject

Returns an array of Team objects

Examples:

NBA::Team.all.first.name                    # => "Atlanta Hawks"
NBA::Team.all.first.division                # => "Southeast Division"
NBA::Team.all.first.founded                 # => 1946
NBA::Team.all.first.players.first.name      # => "Al Horford"
NBA::Team.all.first.players.first.number    # => 15
NBA::Team.all.first.players.first.position  # => ["Forward-center"]


16
17
18
19
20
21
22
23
24
# File 'lib/nba/team.rb', line 16

def self.all
  # Attempt to fetch the result from the Freebase API unless there is a
  # connection error, in which case read from a fixture file
  @all ||= begin
    results_to_team(results_from_freebase)
  rescue Errno::EHOSTUNREACH, Faraday::Error::ConnectionFailed, Faraday::Error::TimeoutError
    results_to_team(results_from_cache)
  end
end

.resetObject



26
27
28
# File 'lib/nba/team.rb', line 26

def self.reset
  @all = nil
end