Sha256: 8081a3dd24905e016dd214024eda220d4250a3e18570cf03c8194305baf9d145

Contents?: true

Size: 1.27 KB

Versions: 211

Compression:

Stored size: 1.27 KB

Contents

module Sportradar
  module Api
    class Mma
      class League < Data
        attr_accessor :response, :id, :event, :name, :alias
        @all_hash = {}
        def self.new(data, **opts)
          existing = @all_hash[data['id']]
          if existing
            existing.update(data)
            existing.add_event(opts[:event])
            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]
          @event    = opts[:event]
          @events_hash = {}

          @id = response['id']

          update(data)
        end

        def events
          @events_hash.values
        end
        def add_event(event)
          @events_hash[event.id] = event if event
        end

        def update(data)
          @name   = response['name']
          @alias  = response['alias']

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


        KEYS_SCHED = ["id", "name", "scheduled", "venue", "league", "fights"]

      end
    end
  end
end

__END__

m = Sportradar::Api::Mma.new
sc = m.schedule;
sc.events.size
e = sc.events.last;
e.league.events.size

Version data entries

211 entries across 211 versions & 1 rubygems

Version Path
sportradar-api-0.19.6 lib/sportradar/api/mma/league.rb
sportradar-api-0.19.5 lib/sportradar/api/mma/league.rb
sportradar-api-0.19.4 lib/sportradar/api/mma/league.rb
sportradar-api-0.19.3 lib/sportradar/api/mma/league.rb
sportradar-api-0.19.2 lib/sportradar/api/mma/league.rb
sportradar-api-0.19.1 lib/sportradar/api/mma/league.rb
sportradar-api-0.19.0 lib/sportradar/api/mma/league.rb
sportradar-api-0.18.1 lib/sportradar/api/mma/league.rb
sportradar-api-0.18.0 lib/sportradar/api/mma/league.rb
sportradar-api-0.17.6 lib/sportradar/api/mma/league.rb
sportradar-api-0.17.5 lib/sportradar/api/mma/league.rb
sportradar-api-0.17.5.pre lib/sportradar/api/mma/league.rb
sportradar-api-0.17.4 lib/sportradar/api/mma/league.rb
sportradar-api-0.17.3 lib/sportradar/api/mma/league.rb
sportradar-api-0.17.2 lib/sportradar/api/mma/league.rb
sportradar-api-0.17.1 lib/sportradar/api/mma/league.rb
sportradar-api-0.17.0 lib/sportradar/api/mma/league.rb
sportradar-api-0.17.0.pre lib/sportradar/api/mma/league.rb
sportradar-api-0.16.1 lib/sportradar/api/mma/league.rb
sportradar-api-0.16.0 lib/sportradar/api/mma/league.rb