Class: FootStats::Match

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

Direct Known Subclasses

RoundMatch

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



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

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

  return response.error if response.error?

  updated_response response, options
end

.parse_response(response) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/foot_stats/match.rb', line 19

def self.parse_response(response)
  response['Partida'].collect do |match|
    match_object = Match.new(
      :source_id     => match['@Id'].to_i,
      :date          => match['Data'],
      :status        => match['Status'],
      :referee       => match['Arbitro'],
      :stadium       => match['Estadio'],
      :city          => match['Cidade'],
      :state         => match['Estado'],
      :country       => match['Pais'],
      :has_statistic => match['TemEstatistica'], # TODO: Need to see boolean
      :has_narration => match['TemNarracao'],    # fields.
      :round         => match['Rodada'],
      :phase         => match['Fase'],
      :cup           => match['Taca'],
      :group         => match['Grupo'],
      :game_number   => match['NumeroJogo'],
      :live          => match['AoVivo']
    )

    match['Equipe'].each do |team|
      if team['@Tipo'] == 'Mandante'
        match_object.home_team            = team['@Id'].to_i
        match_object.home_team_name       = team['@Nome']
        match_object.home_score           = team['@Placar']
        match_object.home_penalties_score = team['@PlacarPenaltis']
      else
        match_object.visitor_team            = team['@Id'].to_i
        match_object.visitor_team_name       = team['@Nome']
        match_object.visitor_score           = team['@Placar']
        match_object.visitor_penalties_score = team['@PlacarPenaltis']
      end
    end

    match_object
  end
end

.resource_keyString

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

Returns:

  • (String)


70
71
72
# File 'lib/foot_stats/match.rb', line 70

def self.resource_key
  'Partidas'
end

.resource_nameString

Return the resource name to request to FootStats.

Returns:

  • (String)


62
63
64
# File 'lib/foot_stats/match.rb', line 62

def self.resource_name
  'ListaPartidas'
end

Instance Method Details

#live(options = {}) ⇒ Live

Return live date of a match

Returns:



86
87
88
# File 'lib/foot_stats/match.rb', line 86

def live(options = {})
  Live.find source_id, options
end

#live=(value) ⇒ boolean

Live setter

Returns:

  • (boolean)


94
95
96
97
98
99
100
# File 'lib/foot_stats/match.rb', line 94

def live=(value)
  if value == 'Sim' || value == true
    @has_live = true
  else
    @has_live = false
  end
end

#live?boolean

Checks if match has live coverage

Returns:

  • (boolean)


106
107
108
# File 'lib/foot_stats/match.rb', line 106

def live?
  @has_live
end

#narrations(options = {}) ⇒ Array

Return the narration from a match

Returns:

  • (Array)


78
79
80
# File 'lib/foot_stats/match.rb', line 78

def narrations(options = {})
  Narration.all(options.merge(match: source_id))
end