2014-03-26 11:09:39 +00:00
|
|
|
# == Schema Information
|
|
|
|
#
|
|
|
|
# Table name: bracketers
|
|
|
|
#
|
|
|
|
# id :integer not null, primary key
|
|
|
|
# column :integer
|
|
|
|
# row :integer
|
|
|
|
# created_at :datetime
|
|
|
|
# updated_at :datetime
|
2020-03-18 03:38:17 +00:00
|
|
|
# bracket_id :integer
|
|
|
|
# match_id :integer
|
|
|
|
# team_id :integer
|
|
|
|
#
|
|
|
|
# Indexes
|
|
|
|
#
|
|
|
|
# index_bracketers_on_match_id (match_id)
|
|
|
|
# index_bracketers_on_team_id (team_id)
|
2014-03-26 11:09:39 +00:00
|
|
|
#
|
|
|
|
|
2014-03-23 00:22:25 +00:00
|
|
|
class Bracketer < ActiveRecord::Base
|
|
|
|
include Exceptions
|
|
|
|
include Extra
|
|
|
|
|
2020-03-16 23:57:47 +00:00
|
|
|
#attr_protected :id, :updated_at, :created_at
|
2014-03-23 00:22:25 +00:00
|
|
|
|
2020-03-26 02:26:30 +00:00
|
|
|
belongs_to :contest, :optional => true
|
|
|
|
belongs_to :match, :optional => true
|
|
|
|
belongs_to :contester, :foreign_key => "team_id", :optional => true
|
2014-03-23 00:22:25 +00:00
|
|
|
|
2019-06-02 01:26:36 +00:00
|
|
|
scope :pos, -> (row, col) { where(row: row, column: col) }
|
2014-03-23 00:22:25 +00:00
|
|
|
|
|
|
|
def to_s
|
|
|
|
if self.match_id
|
|
|
|
if match.match_time.past? and (match.score1 and match.score2)
|
|
|
|
winner = match.score1 > match.score2 ? match.contester1.team : match.contester2.team
|
|
|
|
return "#{self.match.score1} - #{self.match.score2}"
|
|
|
|
else
|
|
|
|
return self.match.match_time.strftime("%H:%M %d/%b")
|
|
|
|
end
|
|
|
|
elsif self.contester
|
|
|
|
return self.contester.to_s[0, 10]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|