schedules_helper.rb 772 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
10
11
module SchedulesHelper
  DAYS = {
    "M": Date.new(2019, 1, 14),
    "T": Date.new(2019, 1, 15),
    "W": Date.new(2019, 1, 16),
    "R": Date.new(2019, 1, 17),
    "F": Date.new(2019, 1, 18),
    "S": Date.new(2019, 1, 19),
    "U": Date.new(2019, 1, 20)
  }.freeze

12
13
  def generate_fullcalender_events(sections)
    sections.map do |s|
14
15
16
17
      s.days.split('').map do |day|
        formatted_date = DAYS[day.to_sym].to_s.tr('-', '')
        time = Time.parse(s.start_time).strftime("%H%M%S")
        endtime = Time.parse(s.end_time).strftime("%H%M%S")
18

19
20
21
        {
          title: s.name,
          start: "#{formatted_date}T#{time}",
Zac Wood's avatar
Zac Wood committed
22
23
24
          end: "#{formatted_date}T#{endtime}",
          crn: s.crn,
          active: true
25
        }
26
      end
27
    end.flatten
28
29
  end
end