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