Class: NBA::Shot

Inherits:
Shale::Mapper
  • Object
show all
Defined in:
lib/nba/shot.rb

Overview

Represents a single shot attempt

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#action_typeString

Returns the shot action type

Examples:

shot.action_type #=> "Jump Shot"

Returns:

  • (String)

    the action type



84
# File 'lib/nba/shot.rb', line 84

attribute :action_type, Shale::Type::String

#game_event_idInteger

Returns the game event ID

Examples:

shot.game_event_id #=> 10

Returns:

  • (Integer)

    the event ID



20
# File 'lib/nba/shot.rb', line 20

attribute :game_event_id, Shale::Type::Integer

#game_idString

Returns the game ID

Examples:

shot.game_id #=> "0022400001"

Returns:

  • (String)

    the game ID



12
# File 'lib/nba/shot.rb', line 12

attribute :game_id, Shale::Type::String

#loc_xInteger

Returns the X coordinate on the court

Examples:

shot.loc_x #=> -22

Returns:

  • (Integer)

    the X coordinate



132
# File 'lib/nba/shot.rb', line 132

attribute :loc_x, Shale::Type::Integer

#loc_yInteger

Returns the Y coordinate on the court

Examples:

shot.loc_y #=> 239

Returns:

  • (Integer)

    the Y coordinate



140
# File 'lib/nba/shot.rb', line 140

attribute :loc_y, Shale::Type::Integer

#minutes_remainingInteger

Returns minutes remaining in period

Examples:

shot.minutes_remaining #=> 10

Returns:

  • (Integer)

    minutes remaining



68
# File 'lib/nba/shot.rb', line 68

attribute :minutes_remaining, Shale::Type::Integer

#periodInteger

Returns the period number

Examples:

shot.period #=> 1

Returns:

  • (Integer)

    the period



60
# File 'lib/nba/shot.rb', line 60

attribute :period, Shale::Type::Integer

#player_idInteger

Returns the player ID

Examples:

shot.player_id #=> 201939

Returns:

  • (Integer)

    the player ID



28
# File 'lib/nba/shot.rb', line 28

attribute :player_id, Shale::Type::Integer

#player_nameString

Returns the player name

Examples:

shot.player_name #=> "Stephen Curry"

Returns:

  • (String)

    the player name



36
# File 'lib/nba/shot.rb', line 36

attribute :player_name, Shale::Type::String

#seconds_remainingInteger

Returns seconds remaining in period

Examples:

shot.seconds_remaining #=> 45

Returns:

  • (Integer)

    seconds remaining



76
# File 'lib/nba/shot.rb', line 76

attribute :seconds_remaining, Shale::Type::Integer

#shot_attempted_flagInteger

Returns whether a shot was attempted

Examples:

shot.shot_attempted_flag #=> 1

Returns:

  • (Integer)

    1 if attempted



148
# File 'lib/nba/shot.rb', line 148

attribute :shot_attempted_flag, Shale::Type::Integer

#shot_distanceInteger

Returns the shot distance in feet

Examples:

shot.shot_distance #=> 26

Returns:

  • (Integer)

    the distance



124
# File 'lib/nba/shot.rb', line 124

attribute :shot_distance, Shale::Type::Integer

#shot_made_flagInteger

Returns whether the shot was made

Examples:

shot.shot_made_flag #=> 1

Returns:

  • (Integer)

    1 if made, 0 if missed



156
# File 'lib/nba/shot.rb', line 156

attribute :shot_made_flag, Shale::Type::Integer

#shot_typeString

Returns the shot type (2PT or 3PT)

Examples:

shot.shot_type #=> "3PT Field Goal"

Returns:

  • (String)

    the shot type



92
# File 'lib/nba/shot.rb', line 92

attribute :shot_type, Shale::Type::String

#shot_zone_areaString

Returns the shot zone area

Examples:

shot.shot_zone_area #=> "Center(C)"

Returns:

  • (String)

    the area



108
# File 'lib/nba/shot.rb', line 108

attribute :shot_zone_area, Shale::Type::String

#shot_zone_basicString

Returns the basic shot zone

Examples:

shot.shot_zone_basic #=> "Above the Break 3"

Returns:

  • (String)

    the zone



100
# File 'lib/nba/shot.rb', line 100

attribute :shot_zone_basic, Shale::Type::String

#shot_zone_rangeString

Returns the shot zone range

Examples:

shot.shot_zone_range #=> "24+ ft."

Returns:

  • (String)

    the range



116
# File 'lib/nba/shot.rb', line 116

attribute :shot_zone_range, Shale::Type::String

#team_idInteger

Returns the team ID

Examples:

shot.team_id #=> 1610612744

Returns:

  • (Integer)

    the team ID



44
# File 'lib/nba/shot.rb', line 44

attribute :team_id, Shale::Type::Integer

#team_nameString

Returns the team name

Examples:

shot.team_name #=> "Golden State Warriors"

Returns:

  • (String)

    the team name



52
# File 'lib/nba/shot.rb', line 52

attribute :team_name, Shale::Type::String

Instance Method Details

#attempted?Boolean

Returns whether a shot was attempted

Examples:

shot.attempted? #=> true

Returns:

  • (Boolean)

    true if attempted



164
165
166
# File 'lib/nba/shot.rb', line 164

def attempted?
  shot_attempted_flag.eql?(1)
end

#gameGame?

Returns the game object for this shot

Examples:

shot.game #=> #<NBA::Game>

Returns:

  • (Game, nil)

    the game object



204
205
206
# File 'lib/nba/shot.rb', line 204

def game
  Games.find(game_id)
end

#made?Boolean

Returns whether the shot was made

Examples:

shot.made? #=> true

Returns:

  • (Boolean)

    true if made



174
175
176
# File 'lib/nba/shot.rb', line 174

def made?
  shot_made_flag.eql?(1)
end

#missed?Boolean

Returns whether the shot was missed

Examples:

shot.missed? #=> false

Returns:

  • (Boolean)

    true if missed



184
185
186
# File 'lib/nba/shot.rb', line 184

def missed?
  shot_made_flag&.zero?
end

#three_pointer?Boolean

Returns whether this is a three-pointer

Examples:

shot.three_pointer? #=> true

Returns:

  • (Boolean)

    true if 3PT shot



194
195
196
# File 'lib/nba/shot.rb', line 194

def three_pointer?
  shot_type&.include?("3PT")
end