Sha256: 0e198e022d1c0acc395e1e207c17f59a9794deb559442e860a8c283a0f9a3e72

Contents?: true

Size: 1.84 KB

Versions: 32

Compression:

Stored size: 1.84 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"]
        set_tournaments

      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

      def set_tournaments
        if response["tournament"]
          if response["tournament"].is_a?(Array)
            @tournaments = response["tournament"].map {|x| Sportradar::Api::Soccer::Tournament.new x }
          elsif response["tournament"].is_a?(Hash)
            @tournaments = [ Sportradar::Api::Soccer::Tournament.new(response["tournament"]) ]
          end
        end
      end

    end
  end
end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
sportradar-api-0.1.38 lib/sportradar/api/soccer/tournament_group.rb
sportradar-api-0.1.37 lib/sportradar/api/soccer/tournament_group.rb
sportradar-api-0.1.36 lib/sportradar/api/soccer/tournament_group.rb
sportradar-api-0.1.35 lib/sportradar/api/soccer/tournament_group.rb
sportradar-api-0.1.34 lib/sportradar/api/soccer/tournament_group.rb
sportradar-api-0.1.33 lib/sportradar/api/soccer/tournament_group.rb
sportradar-api-0.1.32 lib/sportradar/api/soccer/tournament_group.rb
sportradar-api-0.1.31 lib/sportradar/api/soccer/tournament_group.rb
sportradar-api-0.1.30 lib/sportradar/api/soccer/tournament_group.rb
sportradar-api-0.1.29 lib/sportradar/api/soccer/tournament_group.rb
sportradar-api-0.1.28 lib/sportradar/api/soccer/tournament_group.rb
sportradar-api-0.1.27 lib/sportradar/api/soccer/tournament_group.rb
sportradar-api-0.1.26 lib/sportradar/api/soccer/tournament_group.rb
sportradar-api-0.1.25 lib/sportradar/api/soccer/tournament_group.rb
sportradar-api-0.1.24 lib/sportradar/api/soccer/tournament_group.rb
sportradar-api-0.1.23 lib/sportradar/api/soccer/tournament_group.rb
sportradar-api-0.1.22 lib/sportradar/api/soccer/tournament_group.rb
sportradar-api-0.1.21 lib/sportradar/api/soccer/tournament_group.rb
sportradar-api-0.1.19 lib/sportradar/api/soccer/tournament_group.rb
sportradar-api-0.1.18 lib/sportradar/api/soccer/tournament_group.rb