Class: Sportradar::Api::Mma::Event
- Defined in:
- lib/sportradar/api/mma/event.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
-
#id ⇒ Object
Returns the value of attribute id.
-
#league ⇒ Object
Returns the value of attribute league.
-
#name ⇒ Object
Returns the value of attribute name.
-
#response ⇒ Object
Returns the value of attribute response.
-
#scheduled ⇒ Object
Returns the value of attribute scheduled.
-
#venue ⇒ Object
Returns the value of attribute venue.
Instance Method Summary collapse
- #api ⇒ Object
- #fights ⇒ Object
-
#get_stats ⇒ Object
def path_pbp “#{ path_base }/pbp” end.
-
#initialize(data, **opts) ⇒ Event
constructor
A new instance of Event.
- #path_base ⇒ Object
- #path_stats ⇒ Object
- #update(data) ⇒ Object
- #update_fights(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) ⇒ 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
#id ⇒ Object
Returns the value of attribute id.
5 6 7 |
# File 'lib/sportradar/api/mma/event.rb', line 5 def id @id end |
#league ⇒ Object
Returns the value of attribute league.
5 6 7 |
# File 'lib/sportradar/api/mma/event.rb', line 5 def league @league end |
#name ⇒ Object
Returns the value of attribute name.
5 6 7 |
# File 'lib/sportradar/api/mma/event.rb', line 5 def name @name end |
#response ⇒ Object
Returns the value of attribute response.
5 6 7 |
# File 'lib/sportradar/api/mma/event.rb', line 5 def response @response end |
#scheduled ⇒ Object
Returns the value of attribute scheduled.
5 6 7 |
# File 'lib/sportradar/api/mma/event.rb', line 5 def scheduled @scheduled end |
#venue ⇒ Object
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
#api ⇒ Object
55 56 57 |
# File 'lib/sportradar/api/mma/event.rb', line 55 def api @api ||= Sportradar::Api::Mma.new end |
#fights ⇒ Object
18 19 20 |
# File 'lib/sportradar/api/mma/event.rb', line 18 def fights @fights_hash.values end |
#get_stats ⇒ Object
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_base ⇒ Object
37 38 39 |
# File 'lib/sportradar/api/mma/event.rb', line 37 def path_base "events/#{ id }" end |
#path_stats ⇒ Object
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 |