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
-
#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.
-
#nick_name ⇒ Object
Returns the value of attribute nick_name.
-
#out_of ⇒ Object
Returns the value of attribute out_of.
-
#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.
Class Method Summary collapse
Instance Method Summary collapse
- #add_fight(fight) ⇒ Object
- #api ⇒ 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.
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
#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 |
#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 |
#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 |
Class Method Details
.all ⇒ Object
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 |
#api ⇒ Object
67 68 69 |
# File 'lib/sportradar/api/mma/fighter.rb', line 67 def api @api ||= Sportradar::Api::Mma.new end |
#fights ⇒ Object
32 33 34 |
# File 'lib/sportradar/api/mma/fighter.rb', line 32 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
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 |