class MypageTools::WeeklySchedule

Data structure to represent 1 week’s Shifts

Attributes

week_begins[R]

Public Class Methods

new(week_begins, shift_array) click to toggle source
# File lib/mypage_tools/weekly_schedule.rb, line 7
def initialize week_begins, shift_array
        @week_begins = week_begins
        @shift_array = shift_array
end

Public Instance Methods

to_ics() click to toggle source
# File lib/mypage_tools/weekly_schedule.rb, line 12
def to_ics
        cal = Calendar.new
        @shift_array.each do |shift|
                cal.add_event shift.to_ical_event unless shift.not_scheduled?
        end
        cal.publish
        cal_string = cal.to_ical

        # TODO: Extract this elsewhere
        FileUtils.mkdir(SCHEDULE_DIR) unless File.directory?(SCHEDULE_DIR)
        file_name = File.join(SCHEDULE_DIR, "Schedule from #{@week_begins}.ics")
        File.open(file_name, "w") { |io| io.write cal_string }
        print "\nSaving schedule to:\n#{file_name}\n"
end