lib/foot_stats/match.rb in foot_stats-0.0.1 vs lib/foot_stats/match.rb in foot_stats-0.1.0

- old
+ new

@@ -1,19 +1,24 @@ module FootStats class Match < Resource - attr_accessor :source_id, :date, :status, :referee, :stadium, :city, :state - attr_accessor :country, :has_statistic, :has_narration, :round, :phase - attr_accessor :cup, :group, :game_number, :live - attr_accessor :home_team, :home_team_name, :home_score, :home_penalties_score - attr_accessor :visitor_team, :visitor_team_name, :visitor_score, :visitor_penalties_score + attribute_accessor :source_id, :date, :status, :referee, :stadium, :city, :state + attribute_accessor :country, :has_statistic, :has_narration, :round, :phase + attribute_accessor :cup, :group, :game_number, :live + attribute_accessor :home_team, :home_team_name, :home_score, :home_penalties_score + attribute_accessor :visitor_team, :visitor_team_name, :visitor_score, :visitor_penalties_score def self.all(options={}) - request = Request.new(self, :Campeonato => options.fetch(:championship)) - response = request.parse + 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 + + 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'], @@ -68,10 +73,38 @@ # Return the narration from a match # # @return [Array] # - def narrations - Narration.all(match: source_id) + def narrations(options = {}) + Narration.all(options.merge(match: source_id)) + end + + # Return live date of a match + # + # @return [Live] + # + def live(options = {}) + Live.find source_id, options + end + + # Live setter + # + # @return [boolean] + # + def live=(value) + if value == 'Sim' || value == true + @has_live = true + else + @has_live = false + end + end + + # Checks if match has live coverage + # + # @return [boolean] + # + def live? + @has_live end end end \ No newline at end of file