Class: Sportradar::Api::Mma::Competition
- Defined in:
- lib/sportradar/api/mma/competition.rb
Instance Attribute Summary collapse
-
#category ⇒ Object
readonly
Returns the value of attribute category.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#parent_id ⇒ Object
readonly
Returns the value of attribute parent_id.
Instance Method Summary collapse
- #api ⇒ Object
- #get_seasons ⇒ Object
- #ingest_seasons(data) ⇒ Object
-
#initialize(data = {}, league_group: nil, **opts) ⇒ Competition
constructor
A new instance of Competition.
- #parse_season(data) ⇒ Object
-
#path_base ⇒ Object
url path helpers.
- #path_seasons ⇒ Object
- #seasons ⇒ Object
- #update(data, **opts) ⇒ 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 = {}, league_group: nil, **opts) ⇒ Competition
Returns a new instance of Competition.
7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/sportradar/api/mma/competition.rb', line 7 def initialize(data = {}, league_group: nil, **opts) @response = data @id = data["id"] @api = opts[:api] @name = data['name'] if data['name'] @parent_id = data['parent_id'] if data['parent_id'] @category = data['category'] if data['category'] @seasons_hash = {} update(data, **opts) end |
Instance Attribute Details
#category ⇒ Object (readonly)
Returns the value of attribute category.
5 6 7 |
# File 'lib/sportradar/api/mma/competition.rb', line 5 def category @category end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
5 6 7 |
# File 'lib/sportradar/api/mma/competition.rb', line 5 def id @id end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/sportradar/api/mma/competition.rb', line 5 def name @name end |
#parent_id ⇒ Object (readonly)
Returns the value of attribute parent_id.
5 6 7 |
# File 'lib/sportradar/api/mma/competition.rb', line 5 def parent_id @parent_id end |
Instance Method Details
#api ⇒ Object
35 36 37 |
# File 'lib/sportradar/api/mma/competition.rb', line 35 def api @api ||= Sportradar::Api::Mma::Api.new end |
#get_seasons ⇒ Object
47 48 49 50 |
# File 'lib/sportradar/api/mma/competition.rb', line 47 def get_seasons data = api.get_data(path_seasons).to_h ingest_seasons(data) end |
#ingest_seasons(data) ⇒ Object
51 52 53 54 55 |
# File 'lib/sportradar/api/mma/competition.rb', line 51 def ingest_seasons(data) update(data) # TODO parse the rest of the data. keys: ["tournament", "seasons"] data end |
#parse_season(data) ⇒ Object
25 26 27 28 29 |
# File 'lib/sportradar/api/mma/competition.rb', line 25 def parse_season(data) if data['seasons'] create_data(@seasons_hash, data['seasons'], klass: Season, api: api, competition: self) end end |
#path_base ⇒ Object
url path helpers
40 41 42 |
# File 'lib/sportradar/api/mma/competition.rb', line 40 def path_base "competitions/#{ id }" end |
#path_seasons ⇒ Object
44 45 46 |
# File 'lib/sportradar/api/mma/competition.rb', line 44 def path_seasons "#{ path_base }/seasons" end |
#seasons ⇒ Object
31 32 33 |
# File 'lib/sportradar/api/mma/competition.rb', line 31 def seasons @seasons_hash.values end |
#update(data, **opts) ⇒ Object
21 22 23 |
# File 'lib/sportradar/api/mma/competition.rb', line 21 def update(data, **opts) parse_season(data) end |