Class: Sportradar::Api::Mma::Fight

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

Constant Summary collapse

KEYS_SCHED =

def set_pbp(data)

@quarters = parse_into_array_with_options(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

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

#coverageObject

Returns the value of attribute coverage.



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

def coverage
  @coverage
end

#end_methodObject

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_roundObject

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_lengthObject

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

#idObject

Returns the value of attribute id.



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

def id
  @id
end

#match_statusObject

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

#responseObject

Returns the value of attribute response.



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

def response
  @response
end

#scheduled_lengthObject

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

#seasonObject

Returns the value of attribute season.



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

def season
  @season
end

#sport_event_contextObject

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_timeObject

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_confirmedObject

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

#statisticsObject

Returns the value of attribute statistics.



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

def statistics
  @statistics
end

#statusObject

Returns the value of attribute status.



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

def status
  @status
end

#title_fightObject

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

#venueObject

Returns the value of attribute venue.



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

def venue
  @venue
end

#weight_classObject

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

#winnerObject

Returns the value of attribute winner.



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

def winner
  @winner
end

#winner_idObject

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

#apiObject



98
99
100
# File 'lib/sportradar/api/mma/fight.rb', line 98

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

#coverage_levelObject



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

def coverage_level
  'live' if @coverage&.dig('live')
end

#fightersObject



19
20
21
# File 'lib/sportradar/api/mma/fight.rb', line 19

def fighters
  @fighters_hash.values
end

#get_summaryObject



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_baseObject



103
104
105
# File 'lib/sportradar/api/mma/fight.rb', line 103

def path_base
  "sport_events/#{ id }"
end

#path_summaryObject



107
108
109
# File 'lib/sportradar/api/mma/fight.rb', line 107

def path_summary
  "#{ path_base }/summary"
end

#scheduledObject



75
76
77
# File 'lib/sportradar/api/mma/fight.rb', line 75

def scheduled
  @start_time
end

#season_idObject



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_atObject



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

#titleObject



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