Class: Sportradar::Api::Basketball::Ncaamb::Tournament

Inherits:
Data
  • Object
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)
  # @response = data
  @api      = opts[:api]

  @id       = data['id']

  @rounds_hash   = {}
  @brackets_hash = {}

  update(data, **opts)
end

Instance Attribute Details

#endObject

Returns the value of attribute end.



6
7
8
# File 'lib/sportradar/api/basketball/ncaamb/tournament.rb', line 6

def end
  @end
end

#idObject

Returns the value of attribute id.



6
7
8
# File 'lib/sportradar/api/basketball/ncaamb/tournament.rb', line 6

def id
  @id
end

#locationObject

Returns the value of attribute location.



6
7
8
# File 'lib/sportradar/api/basketball/ncaamb/tournament.rb', line 6

def location
  @location
end

#nameObject

Returns the value of attribute name.



6
7
8
# File 'lib/sportradar/api/basketball/ncaamb/tournament.rb', line 6

def name
  @name
end

#responseObject

Returns the value of attribute response.



6
7
8
# File 'lib/sportradar/api/basketball/ncaamb/tournament.rb', line 6

def response
  @response
end

#startObject

Returns the value of attribute start.



6
7
8
# File 'lib/sportradar/api/basketball/ncaamb/tournament.rb', line 6

def start
  @start
end

#statusObject

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

#apiObject



120
121
122
# File 'lib/sportradar/api/basketball/ncaamb/tournament.rb', line 120

def api
  @api ||= Sportradar::Api::Basketball::Ncaamb::Api.new
end

#bracket(id) ⇒ Object



54
55
56
# File 'lib/sportradar/api/basketball/ncaamb/tournament.rb', line 54

def bracket(id)
  @brackets_hash[id]
end

#bracketsObject



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

#gamesObject



35
36
37
# File 'lib/sportradar/api/basketball/ncaamb/tournament.rb', line 35

def games
  rounds.flat_map(&:games)
end

#get_scheduleObject

schedule



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_summaryObject

summary



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_baseObject

url paths



75
76
77
# File 'lib/sportradar/api/basketball/ncaamb/tournament.rb', line 75

def path_base
  "tournaments/#{ id }"
end

#path_scheduleObject



78
79
80
# File 'lib/sportradar/api/basketball/ncaamb/tournament.rb', line 78

def path_schedule
  "#{ path_base }/schedule"
end

#path_summaryObject



82
83
84
# File 'lib/sportradar/api/basketball/ncaamb/tournament.rb', line 82

def path_summary
  "#{ path_base }/summary"
end

#queue_scheduleObject



111
112
113
114
# File 'lib/sportradar/api/basketball/ncaamb/tournament.rb', line 111

def queue_schedule
  url, headers, options, timeout = api.get_request_info(path_schedule)
  {url: url, headers: headers, params: options, timeout: timeout, callback: method(:ingest_schedule)}
end

#queue_summaryObject



97
98
99
100
# File 'lib/sportradar/api/basketball/ncaamb/tournament.rb', line 97

def queue_summary
  url, headers, options, timeout = api.get_request_info(path_summary)
  {url: url, headers: headers, params: options, timeout: timeout, callback: method(:ingest_summary)}
end

#roundsObject



47
48
49
# File 'lib/sportradar/api/basketball/ncaamb/tournament.rb', line 47

def rounds
  @rounds_hash.values
end

#syncObject

data retrieval



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'] # switch to rounds
  update_brackets(data['brackets']) if data['brackets'] # switch to 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

#yearObject



43
44
45
# File 'lib/sportradar/api/basketball/ncaamb/tournament.rb', line 43

def year
  @season&.year || (@start&.-120)&.year
end