Class: Sportradar::Api::Basketball::Ncaamb::Half

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

def self.new(data, **opts)

existing = @all_hash[data['id']]
if existing
  existing.update(data, **opts)
  existing
else
  @all_hash[data['id']] = super
end

end def self.all

@all_hash.values

end



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/sportradar/api/basketball/ncaamb/half.rb', line 21

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

  @id       = response["id"]
  @number   = response['number']
  @sequence = response['sequence']

  @plays_hash = {}

  update(data)
end

Instance Attribute Details

#away_pointsObject

Returns the value of attribute away_points.



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

def away_points
  @away_points
end

#drivesObject

Returns the value of attribute drives.



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

def drives
  @drives
end

#gameObject

Returns the value of attribute game.



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

def game
  @game
end

#home_pointsObject

Returns the value of attribute home_points.



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

def home_points
  @home_points
end

#idObject

Returns the value of attribute id.



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

def id
  @id
end

#numberObject

Returns the value of attribute number.



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

def number
  @number
end

#responseObject

Returns the value of attribute response.



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

def response
  @response
end

#sequenceObject

Returns the value of attribute sequence.



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

def sequence
  @sequence
end

Instance Method Details

#playsObject Also known as: events



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

def plays
  @plays_hash.values
end

#plays_by_type(play_type, *types) ⇒ Object



38
39
40
41
42
43
44
45
# File 'lib/sportradar/api/basketball/ncaamb/half.rb', line 38

def plays_by_type(play_type, *types)
  if types.empty?
    plays.grep(Play.subclass(play_type.delete('_')))
  else
    play_classes = [play_type, *types].map { |type| Play.subclass(type.delete('_')) }
    plays.select { |play| play_classes.any? { |klass| play.kind_of?(klass) } }
  end
end

#update(data, **opts) ⇒ Object



34
35
36
# File 'lib/sportradar/api/basketball/ncaamb/half.rb', line 34

def update(data, **opts)
  create_data(@plays_hash, data.dig('events'), klass: Play, api: @api, half: self)
end