Sha256: 2d8ccb77ea60f4c2b0e72efb208d4b4b98aee6ed8d9a153dbcd20027005c0a8f

Contents?: true

Size: 1.67 KB

Versions: 211

Compression:

Stored size: 1.67 KB

Contents

module Sportradar
  module Api
    class Mma
      class Roster < Data
        attr_accessor :response, :id, :name, :scheduled, :venue

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

          @generated = response['generated']

          @fighters_hash = {}
          @referees_hash = {}
          @judges_hash   = {}

          update(data)
        end

        def fighters
          @fighters_hash ||= update_fighters(response)
          @fighters_hash.values
        end
        def referees
          @referees_hash ||= update_referees(response)
          @referees_hash.values
        end
        def judges
          @judges_hash ||= update_judges(response)
          @judges_hash.values
        end

        def update(data)
          # update_fighters(data)
          # update_referees(data)
          # update_judges(data)

          self
        end

        def update_fighters(data)
          create_data(@fighters_hash, response.dig('fighters', 'fighter'), klass: Fighter, api: api, roster: self)
        end
        def update_referees(data)
          create_data(@referees_hash, response.dig('referees', 'referee'), klass: Referee, api: api, roster: self)
        end
        def update_judges(data)
          create_data(@judges_hash, response.dig('judges', 'judge'), klass: Judge, api: api, roster: self)
        end
        def api
          @api ||= Sportradar::Api::Mma.new
        end

      end
    end
  end
end

__END__

m = Sportradar::Api::Mma.new
sr = m.participants;


sc = m.schedule;
sc.events.size
e = sc.events.last;
e.venue.events.size

Sportradar::Api::Mma::Schedule.new({}, api: m)
Sportradar::Api::Mma::Schedule.new

Version data entries

211 entries across 211 versions & 1 rubygems

Version Path
sportradar-api-0.9.35 lib/sportradar/api/mma/roster.rb
sportradar-api-0.9.34 lib/sportradar/api/mma/roster.rb
sportradar-api-0.9.33 lib/sportradar/api/mma/roster.rb
sportradar-api-0.9.32 lib/sportradar/api/mma/roster.rb
sportradar-api-0.9.31 lib/sportradar/api/mma/roster.rb
sportradar-api-0.9.30 lib/sportradar/api/mma/roster.rb
sportradar-api-0.9.29 lib/sportradar/api/mma/roster.rb
sportradar-api-0.9.28 lib/sportradar/api/mma/roster.rb
sportradar-api-0.9.27 lib/sportradar/api/mma/roster.rb
sportradar-api-0.9.26 lib/sportradar/api/mma/roster.rb
sportradar-api-0.9.25 lib/sportradar/api/mma/roster.rb