Class: Sportradar::Api::Mma::Fighter
- 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
-
#abbreviation ⇒ Object
Returns the value of attribute abbreviation.
-
#born ⇒ Object
Returns the value of attribute born.
-
#first_name ⇒ Object
Returns the value of attribute first_name.
-
#height ⇒ Object
Returns the value of attribute height.
-
#id ⇒ Object
Returns the value of attribute id.
-
#last_name ⇒ Object
Returns the value of attribute last_name.
-
#name ⇒ Object
Returns the value of attribute name.
-
#nick_name ⇒ Object
Returns the value of attribute nick_name.
-
#out_of ⇒ Object
Returns the value of attribute out_of.
-
#qualifier ⇒ Object
Returns the value of attribute qualifier.
-
#reach ⇒ Object
Returns the value of attribute reach.
-
#record ⇒ Object
Returns the value of attribute record.
-
#response ⇒ Object
Returns the value of attribute response.
-
#stance ⇒ Object
Returns the value of attribute stance.
-
#weight ⇒ Object
Returns the value of attribute weight.
Instance Method Summary collapse
- #add_fight(fight) ⇒ Object
- #api ⇒ Object
- #display_name ⇒ Object
- #fights ⇒ Object
- #get_profile ⇒ Object
-
#initialize(data, **opts) ⇒ Fighter
constructor
A new instance of Fighter.
- #path_base ⇒ Object
- #path_profile ⇒ Object
- #update(data, **opts) ⇒ Object
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.
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/sportradar/api/mma/fighter.rb', line 7 def initialize(data, **opts) @response = data @api = opts[:api] @roster = opts[:roster] @fights_hash = {} @id = data['id'] update(data) end |
Instance Attribute Details
#abbreviation ⇒ Object
Returns the value of attribute abbreviation.
5 6 7 |
# File 'lib/sportradar/api/mma/fighter.rb', line 5 def abbreviation @abbreviation end |
#born ⇒ Object
Returns the value of attribute born.
5 6 7 |
# File 'lib/sportradar/api/mma/fighter.rb', line 5 def born @born end |
#first_name ⇒ Object
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 |
#height ⇒ Object
Returns the value of attribute height.
5 6 7 |
# File 'lib/sportradar/api/mma/fighter.rb', line 5 def height @height end |
#id ⇒ Object
Returns the value of attribute id.
5 6 7 |
# File 'lib/sportradar/api/mma/fighter.rb', line 5 def id @id end |
#last_name ⇒ Object
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 |
#name ⇒ Object
Returns the value of attribute name.
5 6 7 |
# File 'lib/sportradar/api/mma/fighter.rb', line 5 def name @name end |
#nick_name ⇒ Object
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_of ⇒ Object
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 |
#qualifier ⇒ Object
Returns the value of attribute qualifier.
5 6 7 |
# File 'lib/sportradar/api/mma/fighter.rb', line 5 def qualifier @qualifier end |
#reach ⇒ Object
Returns the value of attribute reach.
5 6 7 |
# File 'lib/sportradar/api/mma/fighter.rb', line 5 def reach @reach end |
#record ⇒ Object
Returns the value of attribute record.
5 6 7 |
# File 'lib/sportradar/api/mma/fighter.rb', line 5 def record @record end |
#response ⇒ Object
Returns the value of attribute response.
5 6 7 |
# File 'lib/sportradar/api/mma/fighter.rb', line 5 def response @response end |
#stance ⇒ Object
Returns the value of attribute stance.
5 6 7 |
# File 'lib/sportradar/api/mma/fighter.rb', line 5 def stance @stance end |
#weight ⇒ Object
Returns the value of attribute weight.
5 6 7 |
# File 'lib/sportradar/api/mma/fighter.rb', line 5 def weight @weight end |
Instance Method Details
#add_fight(fight) ⇒ Object
21 22 23 |
# File 'lib/sportradar/api/mma/fighter.rb', line 21 def add_fight(fight) @fights_hash[fight.id] = fight if fight end |
#api ⇒ Object
67 68 69 |
# File 'lib/sportradar/api/mma/fighter.rb', line 67 def api @api ||= Sportradar::Api::Mma::Api.new end |
#display_name ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/sportradar/api/mma/fighter.rb', line 25 def display_name if first_name && last_name "#{first_name} #{last_name}" else @name || @short_name end end |
#fights ⇒ Object
18 19 20 |
# File 'lib/sportradar/api/mma/fighter.rb', line 18 def fights @fights_hash.values end |
#get_profile ⇒ Object
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_base ⇒ Object
55 56 57 |
# File 'lib/sportradar/api/mma/fighter.rb', line 55 def path_base "participants/#{ id }" end |
#path_profile ⇒ Object
58 59 60 |
# File 'lib/sportradar/api/mma/fighter.rb', line 58 def path_profile "#{ path_base }/profile" end |
#update(data, **opts) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/sportradar/api/mma/fighter.rb', line 33 def update(data, **opts) @name = data['name'] if data['name'] @abbreviation = data['abbreviation'] if data['abbreviation'] @short_name = data['short_name'] if data['short_name'] @qualifier = data['qualifier'] if data['qualifier'] # "72", @abbreviation = data['abbreviation'] if data['abbreviation'] # "72", @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", @name = data['name'] if data['name'] # "Wang, Sai", @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 |