Class: MypageTools::WeeklySchedule
- Inherits:
-
Object
- Object
- MypageTools::WeeklySchedule
- Includes:
- Icalendar
- Defined in:
- lib/mypage_tools/weekly_schedule.rb
Overview
Data structure to represent 1 week’s Shifts
Instance Attribute Summary collapse
-
#week_begins ⇒ Object
readonly
Returns the value of attribute week_begins.
Instance Method Summary collapse
-
#initialize(week_begins, shift_array) ⇒ WeeklySchedule
constructor
A new instance of WeeklySchedule.
- #to_ics ⇒ Object
Constructor Details
#initialize(week_begins, shift_array) ⇒ WeeklySchedule
Returns a new instance of WeeklySchedule.
7 8 9 10 |
# File 'lib/mypage_tools/weekly_schedule.rb', line 7 def initialize week_begins, shift_array @week_begins = week_begins @shift_array = shift_array end |
Instance Attribute Details
#week_begins ⇒ Object (readonly)
Returns the value of attribute week_begins.
5 6 7 |
# File 'lib/mypage_tools/weekly_schedule.rb', line 5 def week_begins @week_begins end |
Instance Method Details
#to_ics ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# 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 |