Class: Sportradar::Nba::Models::Quarter

Inherits:
Object
  • Object
show all
Defined in:
lib/sportradar/nba/models/quarter.rb

Instance Method Summary collapse

Constructor Details

#initialize(game_id:, attributes:) ⇒ Quarter

Returns a new instance of Quarter.



5
6
7
8
9
# File 'lib/sportradar/nba/models/quarter.rb', line 5

def initialize(game_id:, attributes:)
  @game_id = game_id
  @attributes = attributes
  build_events
end

Instance Method Details

#abbreviationObject



15
16
17
18
19
20
21
22
23
24
# File 'lib/sportradar/nba/models/quarter.rb', line 15

def abbreviation
  case type
  when 'quarter'
    "#{number}Q"
  when 'overtime'
    "#{number}OT"
  else
    "#{number}"
  end
end

#eventsObject



46
47
48
# File 'lib/sportradar/nba/models/quarter.rb', line 46

def events
  @events ||= []
end

#events_dataObject



50
51
52
# File 'lib/sportradar/nba/models/quarter.rb', line 50

def events_data
  @actions ||= @attributes.dig('events') || []
end

#foulsObject



54
55
56
# File 'lib/sportradar/nba/models/quarter.rb', line 54

def fouls
  events.collect(&:foul).compact
end

#game_idObject



26
27
28
# File 'lib/sportradar/nba/models/quarter.rb', line 26

def game_id
  @game_id
end

#idObject



30
31
32
# File 'lib/sportradar/nba/models/quarter.rb', line 30

def id
  @id
end

#numberObject



34
35
36
# File 'lib/sportradar/nba/models/quarter.rb', line 34

def number
  @attributes['number'] || 0
end

#on_court_playersObject



66
67
68
# File 'lib/sportradar/nba/models/quarter.rb', line 66

def on_court_players
  events.map(&:on_court_players).flatten
end

#scoring_playsObject



58
59
60
# File 'lib/sportradar/nba/models/quarter.rb', line 58

def scoring_plays
  events.collect(&:scoring_play).compact
end

#sequenceObject



38
39
40
# File 'lib/sportradar/nba/models/quarter.rb', line 38

def sequence
  @attributes['sequence'] || 0
end

#stoppagesObject



62
63
64
# File 'lib/sportradar/nba/models/quarter.rb', line 62

def stoppages
  events.collect(&:stoppage).compact
end

#to_sObject



11
12
13
# File 'lib/sportradar/nba/models/quarter.rb', line 11

def to_s
  "#{type.titleize} #{number}"
end

#typeObject



42
43
44
# File 'lib/sportradar/nba/models/quarter.rb', line 42

def type
  @attributes['type']
end