Class: Sportradar::Api::Basketball::Ncaamb::Half
- Defined in:
- lib/sportradar/api/basketball/ncaamb/half.rb
Instance Attribute Summary collapse
-
#away_points ⇒ Object
Returns the value of attribute away_points.
-
#drives ⇒ Object
Returns the value of attribute drives.
-
#game ⇒ Object
Returns the value of attribute game.
-
#home_points ⇒ Object
Returns the value of attribute home_points.
-
#id ⇒ Object
Returns the value of attribute id.
-
#number ⇒ Object
Returns the value of attribute number.
-
#response ⇒ Object
Returns the value of attribute response.
-
#sequence ⇒ Object
Returns the value of attribute sequence.
Instance Method Summary collapse
-
#initialize(data, **opts) ⇒ Half
constructor
def self.new(data, **opts) existing = @all_hash[data] if existing existing.update(data, **opts) existing else @all_hash[data] = super end end def self.all @all_hash.values end.
- #plays ⇒ Object (also: #events)
- #plays_by_type(play_type, *types) ⇒ Object
- #update(data, **opts) ⇒ Object
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_points ⇒ Object
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 |
#drives ⇒ Object
Returns the value of attribute drives.
6 7 8 |
# File 'lib/sportradar/api/basketball/ncaamb/half.rb', line 6 def drives @drives end |
#game ⇒ Object
Returns the value of attribute game.
6 7 8 |
# File 'lib/sportradar/api/basketball/ncaamb/half.rb', line 6 def game @game end |
#home_points ⇒ Object
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 |
#id ⇒ Object
Returns the value of attribute id.
6 7 8 |
# File 'lib/sportradar/api/basketball/ncaamb/half.rb', line 6 def id @id end |
#number ⇒ Object
Returns the value of attribute number.
6 7 8 |
# File 'lib/sportradar/api/basketball/ncaamb/half.rb', line 6 def number @number end |
#response ⇒ Object
Returns the value of attribute response.
6 7 8 |
# File 'lib/sportradar/api/basketball/ncaamb/half.rb', line 6 def response @response end |
#sequence ⇒ Object
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
#plays ⇒ Object 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 |