Class: FootStats::Narration
- Defined in:
- lib/foot_stats/narration.rb
Instance Attribute Summary collapse
-
#championship_id ⇒ Object
Returns the value of attribute championship_id.
-
#details ⇒ Object
Returns the value of attribute details.
-
#has_penalty ⇒ Object
Returns the value of attribute has_penalty.
-
#match_id ⇒ Object
Returns the value of attribute match_id.
-
#name ⇒ Object
Returns the value of attribute name.
-
#score ⇒ Object
Returns the value of attribute score.
-
#season ⇒ Object
Returns the value of attribute season.
Class Method Summary collapse
- .all(options = {}) ⇒ Object
- .find(options = {}) ⇒ Object
- .parse_response(response) ⇒ Object
-
.resource_key ⇒ String
Return the resource key that is fetch from the API response.
-
.resource_name ⇒ String
Return the resource name to request to FootStats.
Methods inherited from Resource
Methods included from AttributeAccessor
Constructor Details
This class inherits a constructor from FootStats::Resource
Instance Attribute Details
#championship_id ⇒ Object
Returns the value of attribute championship_id.
3 4 5 |
# File 'lib/foot_stats/narration.rb', line 3 def championship_id @championship_id end |
#details ⇒ Object
Returns the value of attribute details.
3 4 5 |
# File 'lib/foot_stats/narration.rb', line 3 def details @details end |
#has_penalty ⇒ Object
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_id ⇒ Object
Returns the value of attribute match_id.
3 4 5 |
# File 'lib/foot_stats/narration.rb', line 3 def match_id @match_id end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/foot_stats/narration.rb', line 3 def name @name end |
#score ⇒ Object
Returns the value of attribute score.
3 4 5 |
# File 'lib/foot_stats/narration.rb', line 3 def score @score end |
#season ⇒ Object
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(={}) [ self.find() ] end |
.find(options = {}) ⇒ Object
9 10 11 12 13 14 15 16 17 |
# File 'lib/foot_stats/narration.rb', line 9 def self.find(={}) match_id = .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, 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_key ⇒ String
Return the resource key that is fetch from the API response.
62 63 64 |
# File 'lib/foot_stats/narration.rb', line 62 def self.resource_key 'Campeonato' end |
.resource_name ⇒ String
Return the resource name to request to FootStats.
54 55 56 |
# File 'lib/foot_stats/narration.rb', line 54 def self.resource_name 'Narracao' end |