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.17.1 lib/sportradar/api/soccer/standing.rb
sportradar-api-0.17.0 lib/sportradar/api/soccer/standing.rb
sportradar-api-0.17.0.pre lib/sportradar/api/soccer/standing.rb
sportradar-api-0.16.1 lib/sportradar/api/soccer/standing.rb
sportradar-api-0.16.0 lib/sportradar/api/soccer/standing.rb
sportradar-api-0.15.1 lib/sportradar/api/soccer/standing.rb
sportradar-api-0.15.0 lib/sportradar/api/soccer/standing.rb
sportradar-api-0.14.0 lib/sportradar/api/soccer/standing.rb
sportradar-api-0.13.26 lib/sportradar/api/soccer/standing.rb
sportradar-api-0.13.25 lib/sportradar/api/soccer/standing.rb
sportradar-api-0.13.24 lib/sportradar/api/soccer/standing.rb
sportradar-api-0.13.23 lib/sportradar/api/soccer/standing.rb
sportradar-api-0.13.22 lib/sportradar/api/soccer/standing.rb
sportradar-api-0.13.21 lib/sportradar/api/soccer/standing.rb
sportradar-api-0.13.20 lib/sportradar/api/soccer/standing.rb
sportradar-api-0.13.19 lib/sportradar/api/soccer/standing.rb
sportradar-api-0.13.18 lib/sportradar/api/soccer/standing.rb
sportradar-api-0.13.17 lib/sportradar/api/soccer/standing.rb
sportradar-api-0.13.16 lib/sportradar/api/soccer/standing.rb
sportradar-api-0.13.15 lib/sportradar/api/soccer/standing.rb