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 @quartersend
["id", "name", "scheduled", "venue", "league", "fights"]
Instance Attribute Summary collapse
-
#coverage ⇒ Object
Returns the value of attribute coverage.
-
#end_method ⇒ Object
Returns the value of attribute end_method.
-
#final_round ⇒ Object
Returns the value of attribute final_round.
-
#final_round_length ⇒ Object
Returns the value of attribute final_round_length.
-
#id ⇒ Object
Returns the value of attribute id.
-
#match_status ⇒ Object
Returns the value of attribute match_status.
-
#response ⇒ Object
Returns the value of attribute response.
-
#scheduled_length ⇒ Object
Returns the value of attribute scheduled_length.
-
#season ⇒ Object
Returns the value of attribute season.
-
#sport_event_context ⇒ Object
Returns the value of attribute sport_event_context.
-
#start_time ⇒ Object
Returns the value of attribute start_time.
-
#start_time_confirmed ⇒ Object
Returns the value of attribute start_time_confirmed.
-
#statistics ⇒ Object
Returns the value of attribute statistics.
-
#status ⇒ Object
Returns the value of attribute status.
-
#title_fight ⇒ Object
Returns the value of attribute title_fight.
-
#venue ⇒ Object
Returns the value of attribute venue.
-
#weight_class ⇒ Object
Returns the value of attribute weight_class.
-
#winner ⇒ Object
Returns the value of attribute winner.
-
#winner_id ⇒ Object
Returns the value of attribute winner_id.
Instance Method Summary collapse
- #api ⇒ Object
- #coverage_level ⇒ Object
- #fighters ⇒ Object
- #get_summary ⇒ Object
-
#initialize(data, **opts) ⇒ Fight
constructor
A new instance of Fight.
- #path_base ⇒ Object
- #path_summary ⇒ Object
- #scheduled ⇒ Object
- #season_id ⇒ Object
- #starts_at ⇒ Object
- #structure_stats(data) ⇒ Object
- #title ⇒ Object
- #update(data, **opts) ⇒ Object
- #update_fighters(data) ⇒ Object
- #update_statistics(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.
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/sportradar/api/mma/fight.rb', line 7 def initialize(data, **opts) @response = data @api = opts[:api] @season = opts[:season] @fighters_hash = {} @id = data['id'] @statistics = {} update(data) end |
Instance Attribute Details
#coverage ⇒ Object
Returns the value of attribute coverage.
5 6 7 |
# File 'lib/sportradar/api/mma/fight.rb', line 5 def coverage @coverage end |
#end_method ⇒ Object
Returns the value of attribute end_method.
5 6 7 |
# File 'lib/sportradar/api/mma/fight.rb', line 5 def end_method @end_method end |
#final_round ⇒ Object
Returns the value of attribute final_round.
5 6 7 |
# File 'lib/sportradar/api/mma/fight.rb', line 5 def final_round @final_round end |
#final_round_length ⇒ Object
Returns the value of attribute final_round_length.
5 6 7 |
# File 'lib/sportradar/api/mma/fight.rb', line 5 def final_round_length @final_round_length 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 |
#match_status ⇒ Object
Returns the value of attribute match_status.
5 6 7 |
# File 'lib/sportradar/api/mma/fight.rb', line 5 def match_status @match_status 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 |
#scheduled_length ⇒ Object
Returns the value of attribute scheduled_length.
5 6 7 |
# File 'lib/sportradar/api/mma/fight.rb', line 5 def scheduled_length @scheduled_length end |
#season ⇒ Object
Returns the value of attribute season.
5 6 7 |
# File 'lib/sportradar/api/mma/fight.rb', line 5 def season @season end |
#sport_event_context ⇒ Object
Returns the value of attribute sport_event_context.
5 6 7 |
# File 'lib/sportradar/api/mma/fight.rb', line 5 def sport_event_context @sport_event_context end |
#start_time ⇒ Object
Returns the value of attribute start_time.
5 6 7 |
# File 'lib/sportradar/api/mma/fight.rb', line 5 def start_time @start_time end |
#start_time_confirmed ⇒ Object
Returns the value of attribute start_time_confirmed.
5 6 7 |
# File 'lib/sportradar/api/mma/fight.rb', line 5 def start_time_confirmed @start_time_confirmed end |
#statistics ⇒ Object
Returns the value of attribute statistics.
5 6 7 |
# File 'lib/sportradar/api/mma/fight.rb', line 5 def statistics @statistics end |
#status ⇒ Object
Returns the value of attribute status.
5 6 7 |
# File 'lib/sportradar/api/mma/fight.rb', line 5 def status @status end |
#title_fight ⇒ Object
Returns the value of attribute title_fight.
5 6 7 |
# File 'lib/sportradar/api/mma/fight.rb', line 5 def title_fight @title_fight end |
#venue ⇒ Object
Returns the value of attribute venue.
5 6 7 |
# File 'lib/sportradar/api/mma/fight.rb', line 5 def venue @venue 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 |
#winner ⇒ Object
Returns the value of attribute winner.
5 6 7 |
# File 'lib/sportradar/api/mma/fight.rb', line 5 def winner @winner end |
#winner_id ⇒ Object
Returns the value of attribute winner_id.
5 6 7 |
# File 'lib/sportradar/api/mma/fight.rb', line 5 def winner_id @winner_id end |
Instance Method Details
#api ⇒ Object
98 99 100 |
# File 'lib/sportradar/api/mma/fight.rb', line 98 def api @api ||= Sportradar::Api::Mma::Api.new end |
#coverage_level ⇒ Object
67 68 69 |
# File 'lib/sportradar/api/mma/fight.rb', line 67 def coverage_level 'live' if @coverage&.dig('live') end |
#fighters ⇒ Object
19 20 21 |
# File 'lib/sportradar/api/mma/fight.rb', line 19 def fighters @fighters_hash.values end |
#get_summary ⇒ Object
111 112 113 114 115 116 |
# File 'lib/sportradar/api/mma/fight.rb', line 111 def get_summary data = api.get_data(path_summary) update(data) data end |
#path_base ⇒ Object
103 104 105 |
# File 'lib/sportradar/api/mma/fight.rb', line 103 def path_base "sport_events/#{ id }" end |
#path_summary ⇒ Object
107 108 109 |
# File 'lib/sportradar/api/mma/fight.rb', line 107 def path_summary "#{ path_base }/summary" end |
#scheduled ⇒ Object
75 76 77 |
# File 'lib/sportradar/api/mma/fight.rb', line 75 def scheduled @start_time end |
#season_id ⇒ Object
59 60 61 |
# File 'lib/sportradar/api/mma/fight.rb', line 59 def season_id @season&.id || @sport_event_context&.dig('season', 'id') end |
#starts_at ⇒ Object
63 64 65 |
# File 'lib/sportradar/api/mma/fight.rb', line 63 def starts_at @start_time end |
#structure_stats(data) ⇒ Object
94 95 96 |
# File 'lib/sportradar/api/mma/fight.rb', line 94 def structure_stats(data) data['competitors'].map { |comp_data| [comp_data['id'], comp_data.merge(comp_data.delete('statistics'))] }.to_h end |
#title ⇒ Object
71 72 73 |
# File 'lib/sportradar/api/mma/fight.rb', line 71 def title fighters.map(&:display_name).join(' vs ') end |
#update(data, **opts) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/sportradar/api/mma/fight.rb', line 23 def update(data, **opts) if data["summaries"] update(data["summaries"][0]) end if data["sport_event"] update(data["sport_event"]) end if data["sport_event_status"] update(data["sport_event_status"]) end @id = data['id'] if data['id'] && !@id @start_time = Time.parse(data['start_time']) if data['start_time'] @start_time_confirmed = data['start_time_confirmed'] if data['start_time_confirmed'] @sport_event_context = data['sport_event_context'] if data['sport_event_context'] @coverage = data['coverage'] if data['coverage'] @venue = data['venue'] if data['venue'] @status = data['status'] if data['status'] @match_status = data['match_status'] if data['match_status'] @winner_id = data['winner_id'] if data['winner_id'] @final_round = data['final_round'] if data['final_round'] @final_round_length = data['final_round_length'] if data['final_round_length'] @end_method = data['method'] if data['method'] @winner = data['winner'] if data['winner'] @scheduled_length = data['scheduled_length'] if data['scheduled_length'] @weight_class = data['weight_class'] if data['weight_class'] @title_fight = data['title_fight'] if data['title_fight'] update_fighters(data) if data['competitors'] update_statistics(data['statistics']) if data["statistics"] self end |
#update_fighters(data) ⇒ Object
79 80 81 82 83 |
# File 'lib/sportradar/api/mma/fight.rb', line 79 def update_fighters(data) if data['competitors'] create_data(@fighters_hash, data['competitors'], klass: Fighter, api: api, fight: self) end end |
#update_statistics(data) ⇒ Object
85 86 87 88 89 90 91 92 |
# File 'lib/sportradar/api/mma/fight.rb', line 85 def update_statistics(data) @statistics['totals'] = structure_stats(data["totals"]) if data["totals"] if data['periods'] data['periods'].each do |round| @statistics[round['number']] = structure_stats(round) end end end |