Class: Sportradar::Api::Mma::League

Inherits:
Data
  • Object
show all
Defined in:
lib/sportradar/api/mma/league.rb

Constant Summary collapse

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Data

#all_attributes, #attributes, #create_data, #parse_into_array, #parse_into_array_with_options, #parse_out_hashes, #structure_links, #update_data

Constructor Details

#initialize(data, **opts) ⇒ League

Returns a new instance of League.



21
22
23
24
25
26
27
28
29
30
# File 'lib/sportradar/api/mma/league.rb', line 21

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

  @id = response['id']

  update(data)
end

Instance Attribute Details

#aliasObject

Returns the value of attribute alias.



5
6
7
# File 'lib/sportradar/api/mma/league.rb', line 5

def alias
  @alias
end

#eventObject

Returns the value of attribute event.



5
6
7
# File 'lib/sportradar/api/mma/league.rb', line 5

def event
  @event
end

#idObject

Returns the value of attribute id.



5
6
7
# File 'lib/sportradar/api/mma/league.rb', line 5

def id
  @id
end

#nameObject

Returns the value of attribute name.



5
6
7
# File 'lib/sportradar/api/mma/league.rb', line 5

def name
  @name
end

#responseObject

Returns the value of attribute response.



5
6
7
# File 'lib/sportradar/api/mma/league.rb', line 5

def response
  @response
end

Class Method Details

.allObject



17
18
19
# File 'lib/sportradar/api/mma/league.rb', line 17

def self.all
  @all_hash.values
end

.new(data, **opts) ⇒ Object



7
8
9
10
11
12
13
14
15
16
# File 'lib/sportradar/api/mma/league.rb', line 7

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

Instance Method Details

#add_event(event) ⇒ Object



35
36
37
# File 'lib/sportradar/api/mma/league.rb', line 35

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

#apiObject



45
46
47
# File 'lib/sportradar/api/mma/league.rb', line 45

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

#eventsObject



32
33
34
# File 'lib/sportradar/api/mma/league.rb', line 32

def events
  @events_hash.values
end

#update(data) ⇒ Object



39
40
41
42
43
44
# File 'lib/sportradar/api/mma/league.rb', line 39

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

  self
end