Class: Sportradar::Api::Mma::Score

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

Instance Attribute 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) ⇒ Score

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



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

def initialize(data, **opts)
  @response = data
  @api      = opts[:api]
  @result   = opts[:result]

  @id       = data['id']

  update(data)
end

Instance Attribute Details

#first_nameObject

Returns the value of attribute first_name.



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

def first_name
  @first_name
end

#idObject

Returns the value of attribute id.



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

def id
  @id
end

#last_nameObject

Returns the value of attribute last_name.



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

def last_name
  @last_name
end

#loser_scoreObject

Returns the value of attribute loser_score.



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

def loser_score
  @loser_score
end

#responseObject

Returns the value of attribute response.



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

def response
  @response
end

#winner_scoreObject

Returns the value of attribute winner_score.



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

def winner_score
  @winner_score
end

Instance Method Details

#add_fight(fight) ⇒ Object



34
35
36
# File 'lib/sportradar/api/mma/score.rb', line 34

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

#apiObject

def get_profile

data = api.get_data(path_profile)['profile'].dig('fighters', 'fighter')
update(data)
self

end



60
61
62
# File 'lib/sportradar/api/mma/score.rb', line 60

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

#fightsObject



31
32
33
# File 'lib/sportradar/api/mma/score.rb', line 31

def fights
  @fights_hash.values
end

#update(data, **opts) ⇒ Object



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

def update(data, **opts)
  @first_name   = data['first_name']    if data['first_name']
  @last_name    = data['last_name']     if data['last_name']
  @winner_score = data['winner_score']  if data['winner_score']
  @loser_score  = data['loser_score']   if data['loser_score']

  self
end