Sha256: 2e46f8ac1ecdd2c33fe9eb9deb5672e6db518a8ab1ca6f1c88f9b8c631a46377

Contents?: true

Size: 1.5 KB

Versions: 211

Compression:

Stored size: 1.5 KB

Contents

module Sportradar
  module Api
    class Mma
      class Referee < Data
        attr_accessor :response, :id, :first_name, :last_name
        @all_hash = {}
        def self.new(data, **opts)
          existing = @all_hash[data['id']]
          if existing
            existing.update(data, **opts)
            existing.add_fight(opts[:fight])
            existing
          else
            @all_hash[data['id']] = super
          end
        end
        def self.all
          @all_hash.values
        end

        def initialize(data, **opts)
          @response = data
          @api      = opts[:api]
          @roster   = opts[:roster]
          @fights_hash = {}

          @id       = data['id']

          update(data)
        end

        def fights
          @fights_hash.values
        end
        def add_fight(fight)
          @fights_hash[fight.id] = fight if fight
        end


        def update(data, **opts)
          @first_name = data['first_name'] if data['first_name'] # "Sai",
          @last_name  = data['last_name']  if data['last_name']  # "The Boss",

          self
        end

        def api
          @api ||= Sportradar::Api::Mma.new
        end

      end
    end
  end
end

__END__


m = Sportradar::Api::Mma.new
sr = m.participants;
f = sr.fighters.sample;


m = Sportradar::Api::Mma.new
sc = m.schedule;
e = sc.events.sample;
e.fights.first.fighters.first.born

fighter_hash = {'id' => "259117dc-c443-4086-8c1d-abd082e3d4b9" } # => Conor McGregor
f = Sportradar::Api::Mma::Fighter.new(fighter_hash)

Version data entries

211 entries across 211 versions & 1 rubygems

Version Path
sportradar-api-0.9.58 lib/sportradar/api/mma/referee.rb
sportradar-api-0.9.57 lib/sportradar/api/mma/referee.rb
sportradar-api-0.9.56 lib/sportradar/api/mma/referee.rb
sportradar-api-0.9.55 lib/sportradar/api/mma/referee.rb
sportradar-api-0.9.54 lib/sportradar/api/mma/referee.rb
sportradar-api-0.9.53 lib/sportradar/api/mma/referee.rb
sportradar-api-0.9.52 lib/sportradar/api/mma/referee.rb
sportradar-api-0.9.51 lib/sportradar/api/mma/referee.rb
sportradar-api-0.9.50 lib/sportradar/api/mma/referee.rb
sportradar-api-0.9.49 lib/sportradar/api/mma/referee.rb
sportradar-api-0.9.48 lib/sportradar/api/mma/referee.rb
sportradar-api-0.9.47 lib/sportradar/api/mma/referee.rb
sportradar-api-0.9.46 lib/sportradar/api/mma/referee.rb
sportradar-api-0.9.45 lib/sportradar/api/mma/referee.rb
sportradar-api-0.9.41 lib/sportradar/api/mma/referee.rb
sportradar-api-0.9.40 lib/sportradar/api/mma/referee.rb
sportradar-api-0.9.39 lib/sportradar/api/mma/referee.rb
sportradar-api-0.9.38 lib/sportradar/api/mma/referee.rb
sportradar-api-0.9.37 lib/sportradar/api/mma/referee.rb
sportradar-api-0.9.36 lib/sportradar/api/mma/referee.rb