Class: Workarea::Admin::ReleaseEventViewModel

Inherits:
ApplicationViewModel
  • Object
show all
Defined in:
app/view_models/workarea/admin/release_event_view_model.rb

Instance Method Summary collapse

Instance Method Details

#all_day_event?Boolean

Returns:

  • (Boolean)


6
7
8
9
# File 'app/view_models/workarea/admin/release_event_view_model.rb', line 6

def all_day_event?
  return false unless starts_and_ends?
  ends_at - starts_at > 1
end

#descriptionObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/view_models/workarea/admin/release_event_view_model.rb', line 15

def description
  description = [
    I18n.t('workarea.admin.releases.feed.view_release',
      url: release_url(host: Workarea.config.host, id: id))
  ]

  if all_day_event?
    description << I18n.t('workarea.admin.releases.feed.starts_on',
      date: starts_at.strftime('%b %-d, %Y at %r'))
    description << I18n.t('workarea.admin.releases.feed.ends_on',
      date: ends_at.strftime('%b %-d, %Y at %r'))
  end

  unless ends_at.present?
    description << I18n.t('workarea.admin.releases.feed.no_undo_date')
  end

  description.join('\n')
end

#ends_atObject



49
50
51
52
53
# File 'app/view_models/workarea/admin/release_event_view_model.rb', line 49

def ends_at
  return if undo_time.nil?
  time = undo_time.strftime('%Y %m %d %H %M %S').split(' ').map(&:to_i)
  DateTime.civil(*time, undo_time.strftime('%z'))
end

#publish_timeObject



35
36
37
# File 'app/view_models/workarea/admin/release_event_view_model.rb', line 35

def publish_time
  model.publish_at || model.published_at
end

#starts_and_ends?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'app/view_models/workarea/admin/release_event_view_model.rb', line 11

def starts_and_ends?
  starts_at.present? && ends_at.present?
end

#starts_atObject



43
44
45
46
47
# File 'app/view_models/workarea/admin/release_event_view_model.rb', line 43

def starts_at
  return if publish_time.nil?
  time = publish_time.strftime('%Y %m %d %H %M %S').split(' ').map(&:to_i)
  DateTime.civil(*time, publish_time.strftime('%z'))
end

#undo_timeObject



39
40
41
# File 'app/view_models/workarea/admin/release_event_view_model.rb', line 39

def undo_time
  model.undo_at || model.undone_at
end