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.10.18 lib/sportradar/api/mma/roster.rb
sportradar-api-0.10.17 lib/sportradar/api/mma/roster.rb
sportradar-api-0.10.16 lib/sportradar/api/mma/roster.rb
sportradar-api-0.10.15 lib/sportradar/api/mma/roster.rb
sportradar-api-0.10.14 lib/sportradar/api/mma/roster.rb
sportradar-api-0.10.13 lib/sportradar/api/mma/roster.rb
sportradar-api-0.10.12 lib/sportradar/api/mma/roster.rb
sportradar-api-0.10.11 lib/sportradar/api/mma/roster.rb
sportradar-api-0.10.10 lib/sportradar/api/mma/roster.rb
sportradar-api-0.10.9 lib/sportradar/api/mma/roster.rb
sportradar-api-0.10.8 lib/sportradar/api/mma/roster.rb
sportradar-api-0.10.7 lib/sportradar/api/mma/roster.rb
sportradar-api-0.10.6 lib/sportradar/api/mma/roster.rb
sportradar-api-0.10.5 lib/sportradar/api/mma/roster.rb
sportradar-api-0.10.4 lib/sportradar/api/mma/roster.rb
sportradar-api-0.10.3 lib/sportradar/api/mma/roster.rb
sportradar-api-0.10.2 lib/sportradar/api/mma/roster.rb
sportradar-api-0.10.1 lib/sportradar/api/mma/roster.rb
sportradar-api-0.10.0 lib/sportradar/api/mma/roster.rb
sportradar-api-0.9.59 lib/sportradar/api/mma/roster.rb