Class: Sportradar::Api::Basketball::Ncaamb::Tournament
- Inherits:
-
Data
- Object
- Data
- Sportradar::Api::Basketball::Ncaamb::Tournament
show all
- Defined in:
- lib/sportradar/api/basketball/ncaamb/tournament.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, **opts) ⇒ Tournament
Returns a new instance of Tournament.
8
9
10
11
12
13
14
15
16
17
18
|
# File 'lib/sportradar/api/basketball/ncaamb/tournament.rb', line 8
def initialize(data, **opts)
@api = opts[:api]
@id = data['id']
@rounds_hash = {}
@brackets_hash = {}
update(data, **opts)
end
|
Instance Attribute Details
#end ⇒ Object
Returns the value of attribute end.
6
7
8
|
# File 'lib/sportradar/api/basketball/ncaamb/tournament.rb', line 6
def end
@end
end
|
#id ⇒ Object
Returns the value of attribute id.
6
7
8
|
# File 'lib/sportradar/api/basketball/ncaamb/tournament.rb', line 6
def id
@id
end
|
#location ⇒ Object
Returns the value of attribute location.
6
7
8
|
# File 'lib/sportradar/api/basketball/ncaamb/tournament.rb', line 6
def location
@location
end
|
#name ⇒ Object
Returns the value of attribute name.
6
7
8
|
# File 'lib/sportradar/api/basketball/ncaamb/tournament.rb', line 6
def name
@name
end
|
#response ⇒ Object
Returns the value of attribute response.
6
7
8
|
# File 'lib/sportradar/api/basketball/ncaamb/tournament.rb', line 6
def response
@response
end
|
#start ⇒ Object
Returns the value of attribute start.
6
7
8
|
# File 'lib/sportradar/api/basketball/ncaamb/tournament.rb', line 6
def start
@start
end
|
#status ⇒ Object
Returns the value of attribute status.
6
7
8
|
# File 'lib/sportradar/api/basketball/ncaamb/tournament.rb', line 6
def status
@status
end
|
Instance Method Details
#bracket(id) ⇒ Object
54
55
56
|
# File 'lib/sportradar/api/basketball/ncaamb/tournament.rb', line 54
def bracket(id)
@brackets_hash[id]
end
|
#brackets ⇒ Object
51
52
53
|
# File 'lib/sportradar/api/basketball/ncaamb/tournament.rb', line 51
def brackets
@brackets_hash.values
end
|
#game(id) ⇒ Object
39
40
41
|
# File 'lib/sportradar/api/basketball/ncaamb/tournament.rb', line 39
def game(id)
games.detect { |g| g.id == id }
end
|
#games ⇒ Object
35
36
37
|
# File 'lib/sportradar/api/basketball/ncaamb/tournament.rb', line 35
def games
rounds.flat_map(&:games)
end
|
#get_schedule ⇒ Object
107
108
109
110
|
# File 'lib/sportradar/api/basketball/ncaamb/tournament.rb', line 107
def get_schedule
data = api.get_data(path_schedule).to_h
ingest_schedule(data)
end
|
#get_summary ⇒ Object
93
94
95
96
|
# File 'lib/sportradar/api/basketball/ncaamb/tournament.rb', line 93
def get_summary
data = api.get_data(path_summary).to_h
ingest_summary(data)
end
|
#ingest_schedule(data) ⇒ Object
115
116
117
118
|
# File 'lib/sportradar/api/basketball/ncaamb/tournament.rb', line 115
def ingest_schedule(data)
update(data, source: :schedule)
data
end
|
#ingest_summary(data) ⇒ Object
101
102
103
104
|
# File 'lib/sportradar/api/basketball/ncaamb/tournament.rb', line 101
def ingest_summary(data)
update(data, source: :summary)
data
end
|
#path_base ⇒ Object
75
76
77
|
# File 'lib/sportradar/api/basketball/ncaamb/tournament.rb', line 75
def path_base
"tournaments/#{ id }"
end
|
#path_schedule ⇒ Object
78
79
80
|
# File 'lib/sportradar/api/basketball/ncaamb/tournament.rb', line 78
def path_schedule
"#{ path_base }/schedule"
end
|
#path_summary ⇒ Object
82
83
84
|
# File 'lib/sportradar/api/basketball/ncaamb/tournament.rb', line 82
def path_summary
"#{ path_base }/summary"
end
|
#queue_schedule ⇒ Object
111
112
113
114
|
# File 'lib/sportradar/api/basketball/ncaamb/tournament.rb', line 111
def queue_schedule
url, , options, timeout = api.get_request_info(path_schedule)
{url: url, headers: , params: options, timeout: timeout, callback: method(:ingest_schedule)}
end
|
#queue_summary ⇒ Object
97
98
99
100
|
# File 'lib/sportradar/api/basketball/ncaamb/tournament.rb', line 97
def queue_summary
url, , options, timeout = api.get_request_info(path_summary)
{url: url, headers: , params: options, timeout: timeout, callback: method(:ingest_summary)}
end
|
#rounds ⇒ Object
47
48
49
|
# File 'lib/sportradar/api/basketball/ncaamb/tournament.rb', line 47
def rounds
@rounds_hash.values
end
|
#sync ⇒ Object
87
88
89
90
|
# File 'lib/sportradar/api/basketball/ncaamb/tournament.rb', line 87
def sync
get_summary
get_schedule
end
|
#update(data, **opts) ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/sportradar/api/basketball/ncaamb/tournament.rb', line 20
def update(data, **opts)
@season = opts[:season] if opts[:season]
@status = data['status'] if data['status']
@name = data['name'] if data['name']
@location = data['location'] if data['location']
@start = Date.parse(data['start_date']) if data['start_date']
@end = Date.parse(data['end_date']) if data['end_date']
@type = data.dig('season', 'type') if data.dig('season', 'type')
update_rounds(data['rounds']) if data['rounds'] update_brackets(data['brackets']) if data['brackets'] end
|
#update_bracket(id, data) ⇒ Object
57
58
59
60
61
62
63
|
# File 'lib/sportradar/api/basketball/ncaamb/tournament.rb', line 57
def update_bracket(id, data)
if @brackets_hash[id]
@brackets_hash[id].update(data)
else
@brackets_hash[id] = Bracket.new(data, tournament: self)
end
end
|
#update_brackets(data) ⇒ Object
64
65
66
|
# File 'lib/sportradar/api/basketball/ncaamb/tournament.rb', line 64
def update_brackets(data)
create_data(@brackets_hash, data, klass: Round, api: @api, tournament: self)
end
|
#update_rounds(data) ⇒ Object
switch to rounds rounds are either bracketed (bracketed) or not (games)
70
71
72
|
# File 'lib/sportradar/api/basketball/ncaamb/tournament.rb', line 70
def update_rounds(data)
create_data(@rounds_hash, data, klass: Round, api: @api, tournament: self)
end
|
#year ⇒ Object
43
44
45
|
# File 'lib/sportradar/api/basketball/ncaamb/tournament.rb', line 43
def year
@season&.year || (@start&.-120)&.year
end
|