Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

73 lines (55 sloc) 1.314 kb
class Contest
include Mongoid::Document
include Mongoid::Slug
field :name, :type => String
field :tagline, :type => String
field :description, :type => String
field :starting_on, :type => Date
field :voting_on, :type => Date
field :closing_on, :type => Date
slug :name
validates :user, :name, :description, :starting_on, :presence => true
before_create :set_voting_and_closing_dates
embeds_many :entries
belongs_to :user
def set_voting_and_closing_dates
self.voting_on = starting_on + 1.week if self.voting_on.blank?
self.closing_on = voting_on + 1.week if self.closing_on.blank?
end
def state
case
when Time.now.utc >= closing_at then 'closed'
when Time.now.utc >= voting_at then 'voting'
when Time.now.utc >= starting_at then 'open'
else
'pending'
end
end
def pending?
state == 'pending'
end
def open?
state == 'open'
end
def voting?
state == 'voting'
end
def closed?
state == 'closed'
end
def starting_at
starting_on.to_time.utc + 16.hours
end
def voting_at
voting_on.to_time.utc + 16.hours
end
def closing_at
closing_on.to_time.utc + 16.hours
end
def next_state_at
case state
when 'open' then voting_at
when 'voting' then closing_at
end
end
end
Jump to Line
Something went wrong with that request. Please try again.