Class: FootStats::Narration

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

Instance Attribute Summary collapse

Class 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

Instance Attribute Details

#championship_idObject

Returns the value of attribute championship_id.



3
4
5
# File 'lib/foot_stats/narration.rb', line 3

def championship_id
  @championship_id
end

#detailsObject

Returns the value of attribute details.



3
4
5
# File 'lib/foot_stats/narration.rb', line 3

def details
  @details
end

#has_penaltyObject

Returns the value of attribute has_penalty.



3
4
5
# File 'lib/foot_stats/narration.rb', line 3

def has_penalty
  @has_penalty
end

#match_idObject

Returns the value of attribute match_id.



3
4
5
# File 'lib/foot_stats/narration.rb', line 3

def match_id
  @match_id
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/foot_stats/narration.rb', line 3

def name
  @name
end

#scoreObject

Returns the value of attribute score.



3
4
5
# File 'lib/foot_stats/narration.rb', line 3

def score
  @score
end

#seasonObject

Returns the value of attribute season.



3
4
5
# File 'lib/foot_stats/narration.rb', line 3

def season
  @season
end

Class Method Details

.all(options = {}) ⇒ Object



5
6
7
# File 'lib/foot_stats/narration.rb', line 5

def self.all(options={})
  [ self.find(options) ]
end

.find(options = {}) ⇒ Object



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

def self.find(options={})
  match_id = options.fetch(:match)
  request  = Request.new self, :Partida => match_id
  response = request.parse stream_key: "match_narration-#{match_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
# File 'lib/foot_stats/narration.rb', line 19

def self.parse_response(response)
  match_hash = response['Partida']
  # Yeah... FootStats bizarre collection made me do it!
  narrations = [(response['Narracoes'] || {})['Narracao']].flatten.compact

  narration = Narration.new(
    :championship_id => response['@Id'].to_i,
    :name            => response['@Nome'],
    :season          => response['@Temporada'],
    :match_id        => match_hash['@Id'].to_i,
    :score           => match_hash['@Placar'],
    :has_penalty     => match_hash['@TemDisputaPenaltis']
  )

  narration.details = []
  narrations.each do |foot_stats_narration|
    narration.details.push(NarrationDetail.new(
      :source_id        => foot_stats_narration["@Id"].to_i,
      :team_source_id   => foot_stats_narration["IdEquipe"].to_i,
      :team_name        => foot_stats_narration["NomeEquipe"],
      :player_source_id => foot_stats_narration["IdJogador"].to_i,
      :player_name      => foot_stats_narration["NomeJogador"],
      :period           => foot_stats_narration["Periodo"],
      :moment           => foot_stats_narration["Momento"],
      :description      => foot_stats_narration["Descricao"],
      :action           => foot_stats_narration["Acao"]
    ))
  end
  narration
end

.resource_keyString

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

Returns:

  • (String)


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

def self.resource_key
  'Campeonato'
end

.resource_nameString

Return the resource name to request to FootStats.

Returns:

  • (String)


54
55
56
# File 'lib/foot_stats/narration.rb', line 54

def self.resource_name
  'Narracao'
end