Class: Sportradar::Api::Mma::Fight

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

Constant Summary collapse

KEYS_SCHED =

def set_pbp(data)

@quarters = parse_into_array_with_options(selector: data, klass: self.parent::Quarter, api: api, game: self)
@plays  = nil # to clear empty array empty
@quarters

end

["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) ⇒ Fight

Returns a new instance of Fight.



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

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

  @id       = data['id']

  update(data)
end

Instance Attribute Details

#accoladeObject

Returns the value of attribute accolade.



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

def accolade
  @accolade
end

#eventObject

Returns the value of attribute event.



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

def event
  @event
end

#idObject

Returns the value of attribute id.



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

def id
  @id
end

#responseObject

Returns the value of attribute response.



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

def response
  @response
end

#resultObject

Returns the value of attribute result.



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

def result
  @result
end

#scheduled_roundsObject

Returns the value of attribute scheduled_rounds.



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

def scheduled_rounds
  @scheduled_rounds
end

#weight_classObject

Returns the value of attribute weight_class.



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

def weight_class
  @weight_class
end

Class Method Details

.allObject



17
18
19
# File 'lib/sportradar/api/mma/fight.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/fight.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

#apiObject



57
58
59
# File 'lib/sportradar/api/mma/fight.rb', line 57

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

#fightersObject



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

def fighters
  @fighters_hash ||= update_fighters(response)
  @fighters_hash.values
end

#scoreObject



37
38
39
# File 'lib/sportradar/api/mma/fight.rb', line 37

def score
  result.scores
end

#update(data, **opts) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/sportradar/api/mma/fight.rb', line 41

def update(data, **opts)
  @accolade         = data['accolade']         if data['accolade']
  @scheduled_rounds = data['scheduled_rounds'] if data['scheduled_rounds'] # "3",
  @weight_class     = data['weight_class']     if data['weight_class'] # {"id"=>"LW", "weight"=>"146-155", "description"=>"Lightweight"},

  @referee = Referee.new(data['referee'], fight: self, api: api) if data['referee']
  @result = Result.new(data['result'], fight: self, api: api) if data['result']

  update_fighters(data) if data['fighters']

  self
end

#update_fighters(data) ⇒ Object



54
55
56
# File 'lib/sportradar/api/mma/fight.rb', line 54

def update_fighters(data)
  create_data(@fighters_hash, response.dig('fighters', 'fighter'), klass: Fighter, api: api, fight: self)
end