Class: Sportradar::Api::Basketball::Ncaamb::Round

Inherits:
Data
  • Object
show all
Defined in:
lib/sportradar/api/basketball/ncaamb/round.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) ⇒ Round

Returns a new instance of Round.



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/sportradar/api/basketball/ncaamb/round.rb', line 8

def initialize(data, **opts)
  @response   = data
  @api        = opts[:api]
  @tournament = opts[:tournament]

  @id         = data['id']

  @games_hash = {}

  update(data, **opts)
end

Instance Attribute Details

#endObject

Returns the value of attribute end.



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

def end
  @end
end

#idObject

Returns the value of attribute id.



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

def id
  @id
end

#locationObject

Returns the value of attribute location.



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

def location
  @location
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#responseObject

Returns the value of attribute response.



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

def response
  @response
end

#sequenceObject

Returns the value of attribute sequence.



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

def sequence
  @sequence
end

#startObject

Returns the value of attribute start.



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

def start
  @start
end

Instance Method Details

#gamesObject



30
31
32
# File 'lib/sportradar/api/basketball/ncaamb/round.rb', line 30

def games
  @games_hash.values
end

#update(data, **opts) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/sportradar/api/basketball/ncaamb/round.rb', line 20

def update(data, **opts)
  @response = data

  @name     = data['name']            if data['name']
  @sequence = data['sequence']        if data['sequence']

  update_games(data['games'])         if data['games']
  update_brackets(data['bracketed'])  if data['bracketed']
end

#update_brackets(data) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/sportradar/api/basketball/ncaamb/round.rb', line 39

def update_brackets(data)
  data.each do |hash|
    create_data(@games_hash, hash['games'], klass: Game, api: @api, round: self, tournament: @tournament)
    # @tournament.update_bracket(data['bracket'].merge('games' => data['games']))
  end
  # hash = {
  #   "bracket"=>{"id"=>"fc853dd0-4744-4735-9e16-5953a155dc1c", "name"=>"East Regional", "location"=>"Philadelphia, PA, USA"},
  #   'games' => [],
  # }

end

#update_games(data) ⇒ Object



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

def update_games(data)
  create_data(@games_hash, data, klass: Game, api: @api, season: self)
end