Sha256: dfb4a4224ae9ca856a0333af00b8cb725764ad5b0f427c5902a55c4259bcded9

Contents?: true

Size: 572 Bytes

Versions: 2

Compression:

Stored size: 572 Bytes

Contents

class Match < ActiveRecord::Base

  self.primary_key = 'id'

  has_one :winner, :foreign_key => "player_id", primary_key: "winner_id", class_name: "::Player"
  has_one :loser, :foreign_key => "player_id", primary_key: "loser_id", class_name: "::Player"

  (Constants::START_YEAR..Constants::END_YEAR).each do |year|
    scope "in_#{year}".intern, -> { where("extract(year from match_date)=#{year}") }
  end

  scope :slams, -> { where(tourney_level:'G') }
  scope :finals, -> { where(round:'F') }

  def players
    ::Player.where(player_id:[winner_id,loser_id])
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
atpruby-0.1.1 lib/atpruby/match.rb
atpruby-0.1.0 lib/atpruby/match.rb