Sha256: 318bb5b4f5383c42e38d9474da0d047132e76897443ec0a934555e7401f85963

Contents?: true

Size: 1.55 KB

Versions: 88

Compression:

Stored size: 1.55 KB

Contents

module Sportradar
  module Api
    class Ncaafb
      class Team < Data
        attr_accessor :response, :id, :name, :market

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

          case response
          when String
            @id = response
          when Hash
            @id = data['id']
            update(response)
          end
        end
        def full_name
          (market || name) ? [market, name].join(' ') : id
        end
        def update(data)
          @name     = data['name']                  if data['name']
          @market   = data['market']                if data['market']
          @players  = parse_players(data['player']) if data['player']
        end

        def players
          @players ||= get_roster
        end
        alias :roster :players
        def parse_players(data)
          @players = parse_into_array_with_options(selector: data, klass: Sportradar::Api::Ncaafb::Player, api: api, team: self)
        end

        def get_roster
          data = api.get_data(path_roster)['team']
          update(data)
        end

        def path_base
          "teams/#{ id }"
        end
        def path_roster
          "#{ path_base }/roster"
        end


        def api
          @api || Sportradar::Api::Ncaafb.new
        end

      end
    end
  end
end

__END__

sr = Sportradar::Api::Ncaafb.new;
ss = sr.schedule;
teams = ss.weeks(1).games.flat_map(&:teams);
t = teams.first;
ps = t.get_roster; # ps => players


# week_count = ss.weeks.count;
# w1 = ss.weeks.first;
# w1 = ss.weeks(1);

Version data entries

88 entries across 88 versions & 1 rubygems

Version Path
sportradar-api-0.10.55 lib/sportradar/api/ncaafb/team.rb
sportradar-api-0.10.54 lib/sportradar/api/ncaafb/team.rb
sportradar-api-0.10.53 lib/sportradar/api/ncaafb/team.rb
sportradar-api-0.10.52 lib/sportradar/api/ncaafb/team.rb
sportradar-api-0.10.51 lib/sportradar/api/ncaafb/team.rb
sportradar-api-0.10.50 lib/sportradar/api/ncaafb/team.rb
sportradar-api-0.10.49 lib/sportradar/api/ncaafb/team.rb
sportradar-api-0.10.48 lib/sportradar/api/ncaafb/team.rb
sportradar-api-0.10.47 lib/sportradar/api/ncaafb/team.rb
sportradar-api-0.10.46 lib/sportradar/api/ncaafb/team.rb
sportradar-api-0.10.45 lib/sportradar/api/ncaafb/team.rb
sportradar-api-0.10.44 lib/sportradar/api/ncaafb/team.rb
sportradar-api-0.10.43 lib/sportradar/api/ncaafb/team.rb
sportradar-api-0.10.42 lib/sportradar/api/ncaafb/team.rb
sportradar-api-0.10.41 lib/sportradar/api/ncaafb/team.rb
sportradar-api-0.10.40 lib/sportradar/api/ncaafb/team.rb
sportradar-api-0.10.39 lib/sportradar/api/ncaafb/team.rb
sportradar-api-0.10.38 lib/sportradar/api/ncaafb/team.rb
sportradar-api-0.10.37 lib/sportradar/api/ncaafb/team.rb
sportradar-api-0.10.36 lib/sportradar/api/ncaafb/team.rb