diff options
author | Robert Speicher <rspeicher@gmail.com> | 2016-01-01 01:07:11 +0300 |
---|---|---|
committer | Robert Speicher <rspeicher@gmail.com> | 2016-01-13 19:34:58 +0300 |
commit | df496fcaf08b085816a45d31d02f1ea230454b63 (patch) | |
tree | 9d7c23c6c33cc96f4e216db234a8ac63bb8e3581 /app/models/broadcast_message.rb | |
parent | 5a1706791e46fd69a67fcdebfc384a702b00a7ff (diff) |
Update BroadcastMessage model
- Adds default values for `color` and `font` attributes
- Adds `active?`, `started?`, `ended?`, and 'status' methods
Diffstat (limited to 'app/models/broadcast_message.rb')
-rw-r--r-- | app/models/broadcast_message.rb | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/app/models/broadcast_message.rb b/app/models/broadcast_message.rb index da0d8a2d65f..188545f9ae5 100644 --- a/app/models/broadcast_message.rb +++ b/app/models/broadcast_message.rb @@ -22,7 +22,32 @@ class BroadcastMessage < ActiveRecord::Base validates :color, allow_blank: true, color: true validates :font, allow_blank: true, color: true + default_value_for :color, '#E75E40' + default_value_for :font, '#FFFFFF' + def self.current - where("ends_at > :now AND starts_at < :now", now: Time.zone.now).last + where("ends_at > :now AND starts_at <= :now", now: Time.zone.now).last + end + + def active? + started? && !ended? + end + + def started? + Time.zone.now >= starts_at + end + + def ended? + ends_at < Time.zone.now + end + + def status + if active? + 'Active' + elsif ended? + 'Expired' + else + 'Pending' + end end end |