Sha256: 4fb0a1ab38912feb71e1ba683728f85d4a4369f993b289124dd733feea6a10d5

Contents?: true

Size: 1.26 KB

Versions: 55

Compression:

Stored size: 1.26 KB

Contents

module Sportradar
  module Api
    module Soccer
      class Standing < Data
        attr_reader :league_group, :id, :type

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

          @groups_hash = {}

          update(data, **opts)
        end

        def update(data, **opts)
          @type           = data['type']
          @tie_break_rule = data['tie_break_rule'] if data['tie_break_rule']

          if data['groups']
            create_data(@groups_hash, data['groups'], klass: TeamGroup, api: api, identifier: 'name')
          end
        end

        def groups(name = nil)
          @groups_hash.values
        end

        def group(name = nil) # nil represents the complete team listing
          @groups_hash[name]
        end

        def teams
          @groups_hash.values.flat_map(&:teams)
        end

        def team(id)
          @groups_hash.values.flat_map(&:teams).detect { |team| team.id == 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.20.2 lib/sportradar/api/soccer/standing.rb
sportradar-api-0.20.1 lib/sportradar/api/soccer/standing.rb
sportradar-api-0.20.0 lib/sportradar/api/soccer/standing.rb
sportradar-api-0.20.0.pre2 lib/sportradar/api/soccer/standing.rb
sportradar-api-0.20.0.pre lib/sportradar/api/soccer/standing.rb
sportradar-api-0.19.6 lib/sportradar/api/soccer/standing.rb
sportradar-api-0.19.5 lib/sportradar/api/soccer/standing.rb
sportradar-api-0.19.4 lib/sportradar/api/soccer/standing.rb
sportradar-api-0.19.3 lib/sportradar/api/soccer/standing.rb
sportradar-api-0.19.2 lib/sportradar/api/soccer/standing.rb
sportradar-api-0.19.1 lib/sportradar/api/soccer/standing.rb
sportradar-api-0.19.0 lib/sportradar/api/soccer/standing.rb
sportradar-api-0.18.1 lib/sportradar/api/soccer/standing.rb
sportradar-api-0.18.0 lib/sportradar/api/soccer/standing.rb
sportradar-api-0.17.6 lib/sportradar/api/soccer/standing.rb
sportradar-api-0.17.5 lib/sportradar/api/soccer/standing.rb
sportradar-api-0.17.5.pre lib/sportradar/api/soccer/standing.rb
sportradar-api-0.17.4 lib/sportradar/api/soccer/standing.rb
sportradar-api-0.17.3 lib/sportradar/api/soccer/standing.rb
sportradar-api-0.17.2 lib/sportradar/api/soccer/standing.rb