BigW Consortium Gitlab

broadcast_message.rb 786 Bytes
Newer Older
Dmitriy Zaporozhets committed
1 2 3 4 5
# == Schema Information
#
# Table name: broadcast_messages
#
#  id         :integer          not null, primary key
Dmitriy Zaporozhets committed
6
#  message    :text             not null
Dmitriy Zaporozhets committed
7 8 9
#  starts_at  :datetime
#  ends_at    :datetime
#  alert_type :integer
Dmitriy Zaporozhets committed
10 11
#  created_at :datetime
#  updated_at :datetime
12 13
#  color      :string(255)
#  font       :string(255)
Dmitriy Zaporozhets committed
14 15
#

16
class BroadcastMessage < ActiveRecord::Base
17 18
  include Sortable

19
  validates :message, presence: true
20 21
  validates :starts_at, presence: true
  validates :ends_at, presence: true
22

23 24
  validates :color, format: { with: /\A\#[0-9A-Fa-f]{3}{1,2}+\Z/ }, allow_blank: true
  validates :font,  format: { with: /\A\#[0-9A-Fa-f]{3}{1,2}+\Z/ }, allow_blank: true
25

26 27 28
  def self.current
    where("ends_at > :now AND starts_at < :now", now: Time.zone.now).last
  end
29
end