Class: Sportradar::Api::Mma::Fight
- Defined in:
- lib/sportradar/api/mma/fight.rb
Constant Summary collapse
- KEYS_SCHED =
def set_pbp(data)
@quarters = (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
-
#accolade ⇒ Object
Returns the value of attribute accolade.
-
#event ⇒ Object
Returns the value of attribute event.
-
#id ⇒ Object
Returns the value of attribute id.
-
#response ⇒ Object
Returns the value of attribute response.
-
#result ⇒ Object
Returns the value of attribute result.
-
#scheduled_rounds ⇒ Object
Returns the value of attribute scheduled_rounds.
-
#weight_class ⇒ Object
Returns the value of attribute weight_class.
Class Method Summary collapse
Instance Method Summary collapse
- #api ⇒ Object
- #fighters ⇒ Object
-
#initialize(data, **opts) ⇒ Fight
constructor
A new instance of Fight.
- #score ⇒ Object
- #update(data, **opts) ⇒ Object
- #update_fighters(data) ⇒ 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) ⇒ 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
#accolade ⇒ Object
Returns the value of attribute accolade.
5 6 7 |
# File 'lib/sportradar/api/mma/fight.rb', line 5 def accolade @accolade end |
#event ⇒ Object
Returns the value of attribute event.
5 6 7 |
# File 'lib/sportradar/api/mma/fight.rb', line 5 def event @event end |
#id ⇒ Object
Returns the value of attribute id.
5 6 7 |
# File 'lib/sportradar/api/mma/fight.rb', line 5 def id @id end |
#response ⇒ Object
Returns the value of attribute response.
5 6 7 |
# File 'lib/sportradar/api/mma/fight.rb', line 5 def response @response end |
#result ⇒ Object
Returns the value of attribute result.
5 6 7 |
# File 'lib/sportradar/api/mma/fight.rb', line 5 def result @result end |
#scheduled_rounds ⇒ Object
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_class ⇒ Object
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
.all ⇒ Object
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
#api ⇒ Object
57 58 59 |
# File 'lib/sportradar/api/mma/fight.rb', line 57 def api @api ||= Sportradar::Api::Mma.new end |
#fighters ⇒ Object
32 33 34 35 |
# File 'lib/sportradar/api/mma/fight.rb', line 32 def fighters @fighters_hash ||= update_fighters(response) @fighters_hash.values end |
#score ⇒ Object
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 |