Class: MLB::Team

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#ballparkObject (readonly)

Returns the value of attribute ballpark.



6
7
8
# File 'lib/mlb/team.rb', line 6

def ballpark
  @ballpark
end

#divisionObject (readonly)

Returns the value of attribute division.



6
7
8
# File 'lib/mlb/team.rb', line 6

def division
  @division
end

#foundedObject (readonly)

Returns the value of attribute founded.



6
7
8
# File 'lib/mlb/team.rb', line 6

def founded
  @founded
end

#leagueObject (readonly)

Returns the value of attribute league.



6
7
8
# File 'lib/mlb/team.rb', line 6

def league
  @league
end

#logo_urlObject (readonly)

Returns the value of attribute logo_url.



6
7
8
# File 'lib/mlb/team.rb', line 6

def logo_url
  @logo_url
end

#lossesObject (readonly)

Returns the value of attribute losses.



6
7
8
# File 'lib/mlb/team.rb', line 6

def losses
  @losses
end

#managerObject (readonly)

Returns the value of attribute manager.



6
7
8
# File 'lib/mlb/team.rb', line 6

def manager
  @manager
end

#mascotObject (readonly)

Returns the value of attribute mascot.



6
7
8
# File 'lib/mlb/team.rb', line 6

def mascot
  @mascot
end

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/mlb/team.rb', line 6

def name
  @name
end

#playersObject (readonly)

Returns the value of attribute players.



6
7
8
# File 'lib/mlb/team.rb', line 6

def players
  @players
end

#winsObject (readonly)

Returns the value of attribute wins.



6
7
8
# File 'lib/mlb/team.rb', line 6

def wins
  @wins
end

Class Method Details

.allObject

Returns an array of Team objects

Examples:

MLB::Team.all.first.name                    # => "Arizona Diamondbacks"
MLB::Team.all.first.league                  # => "National League"
MLB::Team.all.first.division                # => "National League West"
MLB::Team.all.first.manager                 # => "Bob Melvin"
MLB::Team.all.first.wins                    # => 82
MLB::Team.all.first.losses                  # => 80
MLB::Team.all.first.founded                 # => 1998
MLB::Team.all.first.mascot                  # => nil
MLB::Team.all.first.ballpark                # => "Chase Field"
MLB::Team.all.first.logo_url                # => "http://img.freebase.com/api/trans/image_thumb/wikipedia/images/en_id/13104064"
MLB::Team.all.first.players.first.name      # => "Alex Romero"
MLB::Team.all.first.players.first.number    # => 28
MLB::Team.all.first.players.first.position  # => "Right fielder"


24
25
26
27
28
29
30
31
32
# File 'lib/mlb/team.rb', line 24

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 Faraday::Error::ConnectionFailed, Faraday::Error::TimeoutError
    results_to_team(results_from_cache)
  end
end

.resetObject



34
35
36
# File 'lib/mlb/team.rb', line 34

def self.reset
  @all = nil
end