Messages to completions conversion
This commit is contained in:
@@ -29,7 +29,17 @@ class Completion < ApplicationRecord
|
||||
belongs_to :contestant
|
||||
belongs_to :puzzle
|
||||
|
||||
validates :time_seconds, presence: true
|
||||
validates_numericality_of :time_seconds
|
||||
before_save :add_time_seconds
|
||||
|
||||
validates :display_time_from_start, presence: true, format: { with: /\A((\d\d|\d):\d\d|\d\d|\d):\d\d\z/ }
|
||||
validates :puzzle_id, uniqueness: { scope: :contestant }
|
||||
|
||||
def add_time_seconds
|
||||
arr = display_time_from_start.split(":")
|
||||
if arr.size == 3
|
||||
self.time_seconds = arr[0].to_i * 3600 + arr[1].to_i * 60 + arr[2].to_i
|
||||
elsif arr.size == 2
|
||||
self.time_seconds = arr[0].to_i * 60 + arr[1].to_i
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@@ -3,6 +3,8 @@
|
||||
# Table name: messages
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# author :string
|
||||
# display_time :string
|
||||
# text :string not null
|
||||
# time_seconds :integer not null
|
||||
# created_at :datetime not null
|
||||
@@ -20,5 +22,6 @@
|
||||
class Message < ApplicationRecord
|
||||
belongs_to :contest
|
||||
|
||||
validates :author, presence: true
|
||||
validates :text, presence: true
|
||||
end
|
||||
|
Reference in New Issue
Block a user