Sha256: c7858be4d45b19a3e5580b45689fbc3940673039085d2634edcd02cb1b1cda52

Contents?: true

Size: 1.59 KB

Versions: 59

Compression:

Stored size: 1.59 KB

Contents

module Sportradar
  module Api
    module Basketball
      class Ncaamb
        class Hierarchy < Data
          attr_accessor :response, :id, :name, :alias
          def all_attributes
            [:name, :alias, :conferences, :divisions, :teams]
          end

          def initialize(data, **opts)
            # @response = data
            @api      = opts[:api]

            @id    = data.dig('league', 'id')
            @name  = data.dig('league', 'name')
            @alias = data.dig('league', 'alias')

            @divisions_hash = create_data({}, data['divisions'], klass: Division, hierarchy: self, api: @api)
          end
          def divisions
            @divisions_hash.values
          end
          def division(code_name)
            divisions_by_name[code_name]
          end
          private def divisions_by_name
            @divisions_by_name ||= divisions.map { |d| [d.alias, d] }.to_h
          end
          def conferences
            divisions.flat_map(&:conferences)
          end
          def teams
            conferences.flat_map(&:teams)
          end

          def api
            @api || Sportradar::Api::Basketball::Ncaamb::Api.new
          end

        end
      end
    end
  end
end

__END__

st = sr.standings;

st = sr.standings;
sr = Sportradar::Api::Basketball::Ncaamb.new;
lh = sr.hierarchy;
div = lh.division('D1');
div.teams.count
div.conferences.count
div.conferences.first;
p12 = div.conference('PAC12');
t = p12.team('ARIZ') # => 'id' => "9b166a3f-e64b-4825-bb6b-92c6f0418263"
t = div.teams.sample
res = t.get_roster;
res = t.get_season_stats;

t = lh.teams.first;
t.venue.id

Version data entries

59 entries across 59 versions & 1 rubygems

Version Path
sportradar-api-0.20.2 lib/sportradar/api/basketball/ncaamb/hierarchy.rb
sportradar-api-0.20.1 lib/sportradar/api/basketball/ncaamb/hierarchy.rb
sportradar-api-0.20.0 lib/sportradar/api/basketball/ncaamb/hierarchy.rb
sportradar-api-0.20.0.pre2 lib/sportradar/api/basketball/ncaamb/hierarchy.rb
sportradar-api-0.20.0.pre lib/sportradar/api/basketball/ncaamb/hierarchy.rb
sportradar-api-0.19.6 lib/sportradar/api/basketball/ncaamb/hierarchy.rb
sportradar-api-0.19.5 lib/sportradar/api/basketball/ncaamb/hierarchy.rb
sportradar-api-0.19.4 lib/sportradar/api/basketball/ncaamb/hierarchy.rb
sportradar-api-0.19.3 lib/sportradar/api/basketball/ncaamb/hierarchy.rb
sportradar-api-0.19.2 lib/sportradar/api/basketball/ncaamb/hierarchy.rb
sportradar-api-0.19.1 lib/sportradar/api/basketball/ncaamb/hierarchy.rb
sportradar-api-0.19.0 lib/sportradar/api/basketball/ncaamb/hierarchy.rb
sportradar-api-0.18.1 lib/sportradar/api/basketball/ncaamb/hierarchy.rb
sportradar-api-0.18.0 lib/sportradar/api/basketball/ncaamb/hierarchy.rb
sportradar-api-0.17.6 lib/sportradar/api/basketball/ncaamb/hierarchy.rb
sportradar-api-0.17.5 lib/sportradar/api/basketball/ncaamb/hierarchy.rb
sportradar-api-0.17.5.pre lib/sportradar/api/basketball/ncaamb/hierarchy.rb
sportradar-api-0.17.4 lib/sportradar/api/basketball/ncaamb/hierarchy.rb
sportradar-api-0.17.3 lib/sportradar/api/basketball/ncaamb/hierarchy.rb
sportradar-api-0.17.2 lib/sportradar/api/basketball/ncaamb/hierarchy.rb