Class: Sportradar::Api::Mma::Season
- Inherits:
-
Data
- Object
- Data
- Sportradar::Api::Mma::Season
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_id ⇒ Object
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_date ⇒ Object
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
|
#id ⇒ Object
Returns the value of attribute id.
5
6
7
|
# File 'lib/sportradar/api/mma/season.rb', line 5
def id
@id
end
|
#name ⇒ Object
Returns the value of attribute name.
5
6
7
|
# File 'lib/sportradar/api/mma/season.rb', line 5
def name
@name
end
|
#start_date ⇒ Object
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
|
#year ⇒ Object
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
#api ⇒ Object
53
54
55
|
# File 'lib/sportradar/api/mma/season.rb', line 53
def api
@api ||= Sportradar::Api::Mma::Api.new
end
|
#fighters ⇒ Object
33
34
35
|
# File 'lib/sportradar/api/mma/season.rb', line 33
def fighters
@fighters_hash.values
end
|
#fights ⇒ Object
29
30
31
|
# File 'lib/sportradar/api/mma/season.rb', line 29
def fights
@fights_hash.values
end
|
#future? ⇒ Boolean
37
38
39
|
# File 'lib/sportradar/api/mma/season.rb', line 37
def future?
self.end_date > Time.now
end
|
#get_competitors ⇒ Object
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_summary ⇒ Object
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)
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)
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_base ⇒ Object
58
59
60
|
# File 'lib/sportradar/api/mma/season.rb', line 58
def path_base
"seasons/#{ id }"
end
|
#path_competitors ⇒ Object
75
76
77
|
# File 'lib/sportradar/api/mma/season.rb', line 75
def path_competitors
"#{ path_base }/competitors"
end
|
#path_summary ⇒ Object
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
|