lib/sportradar/api/soccer/match.rb in sportradar-api-0.1.8 vs lib/sportradar/api/soccer/match.rb in sportradar-api-0.1.10
- old
+ new
@@ -1,10 +1,10 @@
module Sportradar
module Api
class Soccer::Match < Data
- attr_accessor :id, :status, :scheduled, :scratched, :season_id, :reference_id, :category, :tournament_group, :tournament, :home, :away, :venue, :round, :coverage, :period, :clock, :referee, :facts, :response
+ attr_accessor :id, :status, :scheduled, :scratched, :season_id, :reference_id, :category, :tournament_group, :tournament, :home, :away, :venue, :round, :coverage, :period, :clock, :referee, :facts, :response, :future_game, :winner
def initialize(data)
@response = data
@id = data["id"]
@reference_id = data["reference_id"]
@@ -20,14 +20,26 @@
@away = Sportradar::Api::Soccer::Team.new data["away"]
@home = Sportradar::Api::Soccer::Team.new data["home"]
@venue = Sportradar::Api::Soccer::Venue.new data["venue"] if data["venue"]
+ @future_game = @scheduled > Time.now.utc
+ @winner = find_winner unless future_game
+
# Actual stats from match summary
@period = data["period"]
@clock = data["clock"]
@referee = OpenStruct.new data["referee"] if data["referee"]
@facts = data["facts"]["fact"].map {|fact| Sportradar::Api::Soccer::Fact.new fact } if data["facts"]
+ end
+
+ def find_winner
+ if @home.winner == 'draw'
+ 'draw'
+ else
+ [@home, @away].find {|team| team.winner == "true" }
+ end
+
end
def period_name
period_names = {"P1" => "Period one", "H" => "Halftime", "P2" => "Period two", "PX1" => "Pre-extra time one", "X1" => "Extra time one", "PX2" => "Pre-extra time two", "X2" => "Extra time two", "PP" => "Pre-penalty", "P" => "Penalty"}
period_names[period] if period