Class: FootStats::Championship

Inherits:
Resource
  • Object
show all
Defined in:
lib/foot_stats/championship.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 = {}) ⇒ Array

Retrieve all championships from FootStats

Returns:

  • (Array)


9
10
11
12
13
14
15
# File 'lib/foot_stats/championship.rb', line 9

def self.all(options = {})
  response = Request.new(self).parse stream_key: 'championships'

  return response.error if response.error?

  updated_response response, options
end

.parse_response(response) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/foot_stats/championship.rb', line 17

def self.parse_response(response)
  response.collect do |championship|
    new(
      :source_id          => championship['@Id'].to_i,
      :name               => championship['@Nome'],
      :has_classification => championship['@TemClassificacao'] == 'True',
      :current_round      => championship['@RodadaATual'].to_i,
      :total_rounds       => championship['@Rodadas'].to_i
    )
  end
end

.resource_keyString

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

Returns:

  • (String)


41
42
43
# File 'lib/foot_stats/championship.rb', line 41

def self.resource_key
  'Campeonato'
end

.resource_nameString

Return the resource name to request to FootStats.

Returns:

  • (String)


33
34
35
# File 'lib/foot_stats/championship.rb', line 33

def self.resource_name
  'ListaCampeonatos'
end

Instance Method Details

#classification(options = {}) ⇒ Array

Return the Championship classification.

Returns:

  • (Array)


49
50
51
# File 'lib/foot_stats/championship.rb', line 49

def classification(options = {})
  ChampionshipClassification.all(options.merge(championship: source_id))
end

#matches(options = {}) ⇒ Array

Return all the Championship matches.

Returns:

  • (Array)


65
66
67
# File 'lib/foot_stats/championship.rb', line 65

def matches(options = {})
  Match.all(options.merge(championship: source_id))
end

#teams(options = {}) ⇒ Array

Return the Championship teams.

Returns:

  • (Array)


57
58
59
# File 'lib/foot_stats/championship.rb', line 57

def teams(options = {})
  Team.all(options.merge(championship: source_id))
end