Class: Sportradar::Api::Mma::Fighter

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

Constant Summary collapse

KEYS_SCHED =
["id", "name", "scheduled", "venue", "league", "fights"]
KEYS_EVENT =
["height", "weight", "reach", "stance", "first_name", "nick_name", "last_name", "record"]

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) ⇒ Fighter

Returns a new instance of Fighter.



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

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

  @id       = data['id']

  update(data)
end

Instance Attribute Details

#bornObject

Returns the value of attribute born.



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

def born
  @born
end

#first_nameObject

Returns the value of attribute first_name.



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

def first_name
  @first_name
end

#heightObject

Returns the value of attribute height.



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

def height
  @height
end

#idObject

Returns the value of attribute id.



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

def id
  @id
end

#last_nameObject

Returns the value of attribute last_name.



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

def last_name
  @last_name
end

#nick_nameObject

Returns the value of attribute nick_name.



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

def nick_name
  @nick_name
end

#out_ofObject

Returns the value of attribute out_of.



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

def out_of
  @out_of
end

#reachObject

Returns the value of attribute reach.



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

def reach
  @reach
end

#recordObject

Returns the value of attribute record.



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

def record
  @record
end

#responseObject

Returns the value of attribute response.



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

def response
  @response
end

#stanceObject

Returns the value of attribute stance.



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

def stance
  @stance
end

#weightObject

Returns the value of attribute weight.



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

def weight
  @weight
end

Class Method Details

.allObject



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

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

Instance Method Details

#add_fight(fight) ⇒ Object



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

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

#apiObject



67
68
69
# File 'lib/sportradar/api/mma/fighter.rb', line 67

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

#fightsObject



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

def fights
  @fights_hash.values
end

#get_profileObject



62
63
64
65
66
# File 'lib/sportradar/api/mma/fighter.rb', line 62

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

#path_baseObject



55
56
57
# File 'lib/sportradar/api/mma/fighter.rb', line 55

def path_base
  "participants/#{ id }"
end

#path_profileObject



58
59
60
# File 'lib/sportradar/api/mma/fighter.rb', line 58

def path_profile
  "#{ path_base }/profile"
end

#update(data, **opts) ⇒ Object



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

def update(data, **opts)
  @height     = data['height']     if data['height']     # "72",
  @weight     = data['weight']     if data['weight']     # "170",
  @reach      = data['reach']      if data['reach']      # "",
  @stance     = data['stance']     if data['stance']     # "",
  @first_name = data['first_name'] if data['first_name'] # "Sai",
  @nick_name  = data['nick_name']  if data['nick_name']  # "The Boss",
  @last_name  = data['last_name']  if data['last_name']  # "Wang",
  @record     = data['record']     if data['record']     # {"wins"=>"6", "losses"=>"4", "draws"=>"1", "no_contests"=>"0"},
  @born       = data['born']       if data['born']       # {"date"=>"1988-01-16", "country_code"=>"UNK", "country"=>"Unknown", "state"=>"", "city"=>""},
  @out_of     = data['out_of']     if data['out_of']     # {"country_code"=>"UNK", "country"=>"Unknown", "state"=>"", "city"=>""}}

  self
end