Class: Sportradar::Api::Mma::Event

Inherits:
Data
  • Object
show all
Defined in:
lib/sportradar/api/mma/event.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) ⇒ Event

Returns a new instance of Event.



7
8
9
10
11
12
13
14
15
16
# File 'lib/sportradar/api/mma/event.rb', line 7

def initialize(data, **opts)
  @response = data
  @api      = opts[:api]
  @fights_hash = {}
  @updated_at = Time.now

  @id         = response['id']
  @name       = response['name']
  update(data)
end

Instance Attribute Details

#idObject

Returns the value of attribute id.



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

def id
  @id
end

#leagueObject

Returns the value of attribute league.



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

def league
  @league
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#responseObject

Returns the value of attribute response.



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

def response
  @response
end

#scheduledObject

Returns the value of attribute scheduled.



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

def scheduled
  @scheduled
end

#venueObject

Returns the value of attribute venue.



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

def venue
  @venue
end

Instance Method Details

#apiObject



55
56
57
# File 'lib/sportradar/api/mma/event.rb', line 55

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

#fightsObject



18
19
20
# File 'lib/sportradar/api/mma/event.rb', line 18

def fights
  @fights_hash.values
end

#get_statsObject

def path_pbp

"#{ path_base }/pbp"

end



47
48
49
50
51
52
53
# File 'lib/sportradar/api/mma/event.rb', line 47

def get_stats
  res = api.get_data(path_stats)
  data = res['summary']
  @updated_at = data['generated']
  update(data.dig('events', 'event'))
  res
end

#path_baseObject



37
38
39
# File 'lib/sportradar/api/mma/event.rb', line 37

def path_base
  "events/#{ id }"
end

#path_statsObject



40
41
42
# File 'lib/sportradar/api/mma/event.rb', line 40

def path_stats
  "#{ path_base }/summary"
end

#update(data) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/sportradar/api/mma/event.rb', line 22

def update(data)
  @scheduled  = Time.parse(data["scheduled"])                     if data["scheduled"]
  @venue      = Venue.new(data['venue'], event: self, api: api)   if data['venue']
  @league     = League.new(data['league'], event: self, api: api) if data['league']
  update_fights(data)

  self
end

#update_fights(data) ⇒ Object



31
32
33
34
# File 'lib/sportradar/api/mma/event.rb', line 31

def update_fights(data)
  return if String === data['fights']
  create_data(@fights_hash, data.dig('fights', 'fight'), klass: Fight, api: api, event: self)
end