Class: Sportradar::Api::Mma::Season

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

Returns a new instance of Season.



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

def initialize(data = {}, league_group: nil, **opts)
  @response     = data
  @id           = data["id"]
  @api          = opts[:api]

  @fights_hash = {}
  @fighters_hash = {}

  update(data, **opts)
end

Instance Attribute Details

#competition_idObject (readonly)

Returns the value of attribute competition_id.



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

def competition_id
  @competition_id
end

#end_dateObject (readonly)

Returns the value of attribute end_date.



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

def end_date
  @end_date
end

#idObject (readonly)

Returns the value of attribute id.



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

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#start_dateObject (readonly)

Returns the value of attribute start_date.



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

def start_date
  @start_date
end

#yearObject (readonly)

Returns the value of attribute year.



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

def year
  @year
end

Instance Method Details

#apiObject



53
54
55
# File 'lib/sportradar/api/mma/season.rb', line 53

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

#fightersObject



33
34
35
# File 'lib/sportradar/api/mma/season.rb', line 33

def fighters
  @fighters_hash.values
end

#fightsObject



29
30
31
# File 'lib/sportradar/api/mma/season.rb', line 29

def fights
  @fights_hash.values
end

#future?Boolean

Returns:

  • (Boolean)


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

def future?
  self.end_date > Time.now
end

#get_competitorsObject



78
79
80
81
# File 'lib/sportradar/api/mma/season.rb', line 78

def get_competitors
  data = api.get_data(path_competitors).to_h
  ingest_competitors(data)
end

#get_summaryObject



65
66
67
68
# File 'lib/sportradar/api/mma/season.rb', line 65

def get_summary
  data = api.get_data(path_summary).to_h
  ingest_summary(data)
end

#ingest_competitors(data) ⇒ Object



82
83
84
85
86
# File 'lib/sportradar/api/mma/season.rb', line 82

def ingest_competitors(data)
  update(data)
  # TODO parse the rest of the data. keys: ["tournament", "seasons"]
  data
end

#ingest_summary(data) ⇒ Object



69
70
71
72
73
# File 'lib/sportradar/api/mma/season.rb', line 69

def ingest_summary(data)
  update(data)
  # TODO parse the rest of the data. keys: ["tournament", "seasons"]
  data
end

#parse_competitors(data) ⇒ Object



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

def parse_competitors(data)
  if data['season_competitors']
    create_data(@fighters_hash, data['season_competitors'], klass: Fighter, api: api, season: self)
  end
end

#parse_summary(data) ⇒ Object



41
42
43
44
45
# File 'lib/sportradar/api/mma/season.rb', line 41

def parse_summary(data)
  if data['summaries']
    create_data(@fights_hash, data['summaries'], klass: Fight, api: api, season: self)
  end
end

#path_baseObject

url path helpers



58
59
60
# File 'lib/sportradar/api/mma/season.rb', line 58

def path_base
  "seasons/#{ id }"
end

#path_competitorsObject



75
76
77
# File 'lib/sportradar/api/mma/season.rb', line 75

def path_competitors
  "#{ path_base }/competitors"
end

#path_summaryObject



62
63
64
# File 'lib/sportradar/api/mma/season.rb', line 62

def path_summary
  "#{ path_base }/summaries"
end

#update(data, **opts) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'lib/sportradar/api/mma/season.rb', line 18

def update(data, **opts)
  @name           = data['name']            if data['name']
  @start_date     = Time.parse(data['start_date'])      if data['start_date']
  @end_date       = Time.parse(data['end_date'])        if data['end_date']
  @year           = data['year']            if data['year']
  @competition_id = data['competition_id']  if data['competition_id']

  parse_summary(data)
  parse_competitors(data)
end