Sha256: 48bf4a7a005a436772c096b03b33fc47cb0f30b4b7fa79032a7d66c2288588be

Contents?: true

Size: 1.48 KB

Versions: 55

Compression:

Stored size: 1.48 KB

Contents

module Sportradar
  module Api
    module Soccer
      class TeamGroup < Data
        attr_reader :league_group, :id, :name, :tournament_id

        def initialize(data = {}, league_group: nil, **opts)
          @response     = data
          @id           = data["id"] || data['name']
          @api          = opts[:api]
          @league_group = league_group || data['league_group'] || @api&.league_group

          @teams_hash = {}

          update(data, **opts)
        end

        def update(data, **opts)
          @name           = data['name']
          get_tournament_id(data, **opts)

          if team_data = (data['teams'] || data['team_standings'])
            create_data(@teams_hash, team_data, klass: Team, api: api, tournament: opts[:tournament], team_group: self)
          end
        end

        def get_tournament_id(data, **opts)
          @tournament_id ||= if opts[:tournament]
            opts[:tournament].id
          elsif opts[:season]
            opts[:season].tournament_id
          elsif opts[:match]
            opts[:match].tournament_id
          elsif data['tournament']
            data.dig('tournament', 'id')
          elsif data['season']
            data.dig('season', 'tournament_id')
          end
        end


        def teams
          @teams_hash.values
        end

        def team(id)
          @teams_hash[id]
        end

        def api
          @api ||= Sportradar::Api::Soccer::Api.new(league_group: @league_group)
        end

      end
    end
  end
end

Version data entries

55 entries across 55 versions & 1 rubygems

Version Path
sportradar-api-0.17.1 lib/sportradar/api/soccer/team_group.rb
sportradar-api-0.17.0 lib/sportradar/api/soccer/team_group.rb
sportradar-api-0.17.0.pre lib/sportradar/api/soccer/team_group.rb
sportradar-api-0.16.1 lib/sportradar/api/soccer/team_group.rb
sportradar-api-0.16.0 lib/sportradar/api/soccer/team_group.rb
sportradar-api-0.15.1 lib/sportradar/api/soccer/team_group.rb
sportradar-api-0.15.0 lib/sportradar/api/soccer/team_group.rb
sportradar-api-0.14.0 lib/sportradar/api/soccer/team_group.rb
sportradar-api-0.13.26 lib/sportradar/api/soccer/team_group.rb
sportradar-api-0.13.25 lib/sportradar/api/soccer/team_group.rb
sportradar-api-0.13.24 lib/sportradar/api/soccer/team_group.rb
sportradar-api-0.13.23 lib/sportradar/api/soccer/team_group.rb
sportradar-api-0.13.22 lib/sportradar/api/soccer/team_group.rb
sportradar-api-0.13.21 lib/sportradar/api/soccer/team_group.rb
sportradar-api-0.13.20 lib/sportradar/api/soccer/team_group.rb
sportradar-api-0.13.19 lib/sportradar/api/soccer/team_group.rb
sportradar-api-0.13.18 lib/sportradar/api/soccer/team_group.rb
sportradar-api-0.13.17 lib/sportradar/api/soccer/team_group.rb
sportradar-api-0.13.16 lib/sportradar/api/soccer/team_group.rb
sportradar-api-0.13.15 lib/sportradar/api/soccer/team_group.rb