Class: Announcement

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/announcement.rb

Constant Summary collapse

INACTIVE =
'inactive'
PAST =
'past'
CURRENT =
'current'
FUTURE =
'future'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.activeObject



37
38
39
# File 'app/models/announcement.rb', line 37

def active
  where(active: true)
end

.new_with_defaultsObject



41
42
43
44
45
46
47
48
49
# File 'app/models/announcement.rb', line 41

def new_with_defaults
  new do |ann|
    ann.active = UserAnnouncements[:default_active]
    ann.starts_at = UserAnnouncements[:default_starts_at]
    ann.ends_at = UserAnnouncements[:default_ends_at]
    ann.roles = Array(UserAnnouncements[:default_roles])
    ann.style = UserAnnouncements[:default_style]
  end
end

Instance Method Details

#current?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'app/models/announcement.rb', line 23

def current?
  status == CURRENT
end

#starts_at_for_userObject



27
28
29
# File 'app/models/announcement.rb', line 27

def starts_at_for_user
  starts_at || created_at
end

#statusObject



14
15
16
17
18
19
20
21
# File 'app/models/announcement.rb', line 14

def status
  case
  when active.presence.nil? then INACTIVE
  when ends_at.try(:past?) then PAST
  when starts_at.try(:future?) then FUTURE
  else CURRENT
  end
end

#status_orderObject



31
32
33
# File 'app/models/announcement.rb', line 31

def status_order
  { FUTURE => 1, CURRENT => 2, PAST => 3, INACTIVE => 4 }[status]
end