Sha256: 3845ebbba91b9422ae488d65a4fce53341192be6db5f44295d20bdd443fa8946

Contents?: true

Size: 1.57 KB

Versions: 188

Compression:

Stored size: 1.57 KB

Contents

module Sportradar
  module Api
    class Soccer::TournamentGroup < Data
      attr_accessor :response, :id, :name, :season_start, :season_end, :season, :reference_id, :top_goals, :top_own_goals, :top_assists, :top_cards, :top_points, :tournaments

      def initialize(data)
        @response = data
        @id = data["id"]
        @name = data["name"]
        @season_start = data["season_start"]
        @season_end = data["season_end"]
        @season = data["season"]
        @reference_id = data["reference_id"]
        @top_goals = parse_players(data["top_goals"]["player"]) if data["top_goals"] && data["top_goals"]["player"]
        @top_own_goals = parse_players(data["top_own_goals"]["player"]) if data["top_own_goals"] && data["top_own_goals"]["player"]
        @top_assists = parse_players(data["top_assists"]["player"]) if data["top_assists"] && data["top_assists"]["player"]
        @top_cards = parse_players(data["top_cards"]["player"]) if data["top_cards"] && data["top_cards"]["player"]
        @top_points = parse_players(data["top_points"]["player"]) if data["top_points"] && data["top_points"]["player"]
        @tournaments = parse_into_array(selector: response["tournament"], klass: Sportradar::Api::Soccer::Tournament)  if response["tournament"]
      end

      private

      def parse_players(field_to_parse)
        if field_to_parse.is_a?(Array)
          field_to_parse.map {|player| Sportradar::Api::Soccer::Player.new player }
        elsif field_to_parse.is_a?(Hash)
          [ Sportradar::Api::Soccer::Player.new(field_to_parse) ]
        end
      end


    end
  end
end

Version data entries

188 entries across 188 versions & 1 rubygems

Version Path
sportradar-api-0.13.4 lib/sportradar/api/soccer-old/tournament_group.rb
sportradar-api-0.13.3 lib/sportradar/api/soccer-old/tournament_group.rb
sportradar-api-0.13.2 lib/sportradar/api/soccer-old/tournament_group.rb
sportradar-api-0.13.1 lib/sportradar/api/soccer-old/tournament_group.rb
sportradar-api-0.13.0 lib/sportradar/api/soccer-old/tournament_group.rb
sportradar-api-0.12.3 lib/sportradar/api/soccer/tournament_group.rb
sportradar-api-0.12.2 lib/sportradar/api/soccer/tournament_group.rb
sportradar-api-0.12.1 lib/sportradar/api/soccer/tournament_group.rb
sportradar-api-0.12.0 lib/sportradar/api/soccer/tournament_group.rb
sportradar-api-0.11.69 lib/sportradar/api/soccer/tournament_group.rb
sportradar-api-0.11.68 lib/sportradar/api/soccer/tournament_group.rb
sportradar-api-0.11.67 lib/sportradar/api/soccer/tournament_group.rb
sportradar-api-0.11.66 lib/sportradar/api/soccer/tournament_group.rb
sportradar-api-0.11.65 lib/sportradar/api/soccer/tournament_group.rb
sportradar-api-0.11.64 lib/sportradar/api/soccer/tournament_group.rb
sportradar-api-0.11.63 lib/sportradar/api/soccer/tournament_group.rb
sportradar-api-0.11.62 lib/sportradar/api/soccer/tournament_group.rb
sportradar-api-0.11.61 lib/sportradar/api/soccer/tournament_group.rb
sportradar-api-0.11.60 lib/sportradar/api/soccer/tournament_group.rb
sportradar-api-0.11.59 lib/sportradar/api/soccer/tournament_group.rb