BigW Consortium Gitlab

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

16
class BroadcastMessage < ActiveRecord::Base
17
  attr_accessible :alert_type, :color, :ends_at, :font, :message, :starts_at
18 19

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

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

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