Class: Sportradar::Api::Mma::Competition

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

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 = {}, 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

#categoryObject (readonly)

Returns the value of attribute category.



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

def category
  @category
end

#idObject (readonly)

Returns the value of attribute id.



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

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#parent_idObject (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

#apiObject



35
36
37
# File 'lib/sportradar/api/mma/competition.rb', line 35

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

#get_seasonsObject



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_baseObject

url path helpers



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

def path_base
  "competitions/#{ id }"
end

#path_seasonsObject



44
45
46
# File 'lib/sportradar/api/mma/competition.rb', line 44

def path_seasons
  "#{ path_base }/seasons"
end

#seasonsObject



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