Add contest duration & complete ranking mode implementation
This commit is contained in:
@@ -4,6 +4,8 @@
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# allow_registration :boolean default(FALSE)
|
||||
# duration :string
|
||||
# duration_seconds :integer
|
||||
# lang :string default("en")
|
||||
# name :string
|
||||
# offline_form :boolean default(FALSE)
|
||||
@@ -37,9 +39,19 @@ class Contest < ApplicationRecord
|
||||
|
||||
friendly_id :name, use: :slugged
|
||||
|
||||
before_save :add_duration_seconds
|
||||
|
||||
validates :name, presence: true
|
||||
validates :lang, inclusion: { in: Languages::AVAILABLE_LANGUAGES.map { |lang| lang[:id] } }
|
||||
validates :ranking_mode, inclusion: { in: Ranking::AVAILABLE_RANKING_MODES.map { |lang| lang[:id] } }
|
||||
validates :duration, format: { with: /\A(\d\d:\d\d|\d:\d\d)\z/ }
|
||||
|
||||
generates_token_for :token
|
||||
|
||||
def add_duration_seconds
|
||||
arr = self.duration.split(":")
|
||||
if arr.size == 2
|
||||
self.duration_seconds = arr[0].to_i * 3600 + arr[1].to_i * 60
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user