Class: FootStats::Team

Inherits:
Resource show all
Defined in:
lib/foot_stats/team.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Resource

#initialize, updated_response

Methods included from AttributeAccessor

#attributes, included

Constructor Details

This class inherits a constructor from FootStats::Resource

Class Method Details

.all(options = {}) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/foot_stats/team.rb', line 13

def self.all(options={})
  championship_id = options.fetch(:championship)
  request  = Request.new self, :IdCampeonato => options.fetch(:championship)
  response = request.parse stream_key: "team-championship-#{championship_id}"

  return response.error if response.error?

  updated_response response, options
end

.parse_response(response) ⇒ Object



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

def self.parse_response(response)
  response.collect do |team|
    Team.new(
      :source_id => team['@Id'].to_i,
      :full_name => team['@Nome'],
      :city      => team['@Cidade'],
      :country   => team['@Pais']
    )
  end
end

.resource_keyString

Return the resource key that is fetch from the API response.

Returns:

  • (String)


46
47
48
# File 'lib/foot_stats/team.rb', line 46

def self.resource_key
  'Equipe'
end

.resource_nameString

Return the resource name to request to FootStats.

Returns:

  • (String)


38
39
40
# File 'lib/foot_stats/team.rb', line 38

def self.resource_name
  'ListaEquipesCampeonato'
end

Instance Method Details

#players(options = {}) ⇒ Array

Return all possible team players

Returns:

  • (Array)


9
10
11
# File 'lib/foot_stats/team.rb', line 9

def players(options = {})
  Player.all(options.merge(team: source_id))
end