Sha256: ee3485734c75fbc08a2c89d3ba9481a8618d902080be260b3ba14bc730e101cb

Contents?: true

Size: 952 Bytes

Versions: 3

Compression:

Stored size: 952 Bytes

Contents

class Player < ActiveRecord::Base

  self.primary_key = 'player_id'

  has_many :wins, :foreign_key => "winner_id", class_name: "::Match"
  has_many :losses, :foreign_key => "loser_id", class_name: "::Match"
  has_many :rankings, :foreign_key => "player_id", class_name: "::Ranking"

  def name
    [self.firstname, self.lastname].join(' ')
  end

  def matches
    wins.union(losses)
  end

  def h2h opponent
    return if opponent.nil?
    w = wins.where(loser_id:opponent.player_id).count
    l = losses.where(winner_id:opponent.player_id).count
    "#{w}-#{l}"
  end

  def h2h_details opponent
    return if opponent.nil?
    w = wins.where(loser_id:opponent.player_id)
    l = losses.where(winner_id:opponent.player_id)
    w.union(l)
  end

  def slams
    wins.where(tourney_level:'G',round:'F')
  end

  def slam_finals
    w = wins.where(tourney_level:'G',round:'F')
    l = losses.where(tourney_level:'G',round:'F')
    w.union(l)
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
atpruby-0.1.2 lib/atpruby/player.rb
atpruby-0.1.1 lib/atpruby/player.rb
atpruby-0.1.0 lib/atpruby/player.rb