Class: Sportradar::Api::Mma::League
- Defined in:
- lib/sportradar/api/mma/league.rb
Constant Summary collapse
- KEYS_SCHED =
["id", "name", "scheduled", "venue", "league", "fights"]
Instance Attribute Summary collapse
-
#alias ⇒ Object
Returns the value of attribute alias.
-
#event ⇒ Object
Returns the value of attribute event.
-
#id ⇒ Object
Returns the value of attribute id.
-
#name ⇒ Object
Returns the value of attribute name.
-
#response ⇒ Object
Returns the value of attribute response.
Class Method Summary collapse
Instance Method Summary collapse
- #add_event(event) ⇒ Object
- #api ⇒ Object
- #events ⇒ Object
-
#initialize(data, **opts) ⇒ League
constructor
A new instance of League.
- #update(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) ⇒ League
Returns a new instance of League.
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/sportradar/api/mma/league.rb', line 21 def initialize(data, **opts) @response = data @api = opts[:api] @event = opts[:event] @events_hash = {} @id = response['id'] update(data) end |
Instance Attribute Details
#alias ⇒ Object
Returns the value of attribute alias.
5 6 7 |
# File 'lib/sportradar/api/mma/league.rb', line 5 def alias @alias end |
#event ⇒ Object
Returns the value of attribute event.
5 6 7 |
# File 'lib/sportradar/api/mma/league.rb', line 5 def event @event end |
#id ⇒ Object
Returns the value of attribute id.
5 6 7 |
# File 'lib/sportradar/api/mma/league.rb', line 5 def id @id end |
#name ⇒ Object
Returns the value of attribute name.
5 6 7 |
# File 'lib/sportradar/api/mma/league.rb', line 5 def name @name end |
#response ⇒ Object
Returns the value of attribute response.
5 6 7 |
# File 'lib/sportradar/api/mma/league.rb', line 5 def response @response end |
Class Method Details
.all ⇒ Object
17 18 19 |
# File 'lib/sportradar/api/mma/league.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/league.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
#add_event(event) ⇒ Object
35 36 37 |
# File 'lib/sportradar/api/mma/league.rb', line 35 def add_event(event) @events_hash[event.id] = event if event end |
#api ⇒ Object
45 46 47 |
# File 'lib/sportradar/api/mma/league.rb', line 45 def api @api ||= Sportradar::Api::Mma.new end |
#events ⇒ Object
32 33 34 |
# File 'lib/sportradar/api/mma/league.rb', line 32 def events @events_hash.values end |
#update(data) ⇒ Object
39 40 41 42 43 44 |
# File 'lib/sportradar/api/mma/league.rb', line 39 def update(data) @name = response['name'] @alias = response['alias'] self end |