lib/sportradar/api/soccer/schedule.rb in sportradar-api-0.1.17 vs lib/sportradar/api/soccer/schedule.rb in sportradar-api-0.1.18
- old
+ new
@@ -3,20 +3,30 @@
class Soccer::Schedule < Data
attr_accessor :response, :matches
def initialize(data)
@response = data
- @matches = data["schedule"]["matches"]["match"].map {|x| Sportradar::Api::Soccer::Match.new x } if data["schedule"]["matches"]["match"]
+ set_matches
end
def league(league_name)
matches.select{ |match| match.tournament_group.name.parameterize == league_name.parameterize}
end
def available_leagues
matches.map {|match| match.tournament_group.name}.uniq
end
+ private
+ def set_matches
+ if response["schedule"]["matches"]["match"]
+ if response["schedule"]["matches"]["match"].is_a?(Array)
+ @matches = response["schedule"]["matches"]["match"].map {|x| Sportradar::Api::Soccer::Match.new x }
+ elsif response["schedule"]["matches"]["match"].is_a?(Hash)
+ @matches = [ Sportradar::Api::Soccer::Match.new(response["schedule"]["matches"]["match"]) ]
+ end
+ end
+ end
end
end
end