23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/run_ical.rb', line 23
def generate
description = @program.const_get(:DESCRIPTION)
data = @program.const_get(:DATA)
cal = Icalendar::Calendar.new
cal.x_wr_calname = "#{description} for #{@race_date}"
start_date_padding = @race_date.saturday? ? 2 : 1
start_date = @race_date - (data.size - start_date_padding).days
date_list = (start_date..@race_date).to_a
date_list.each.with_index do |date, index|
activity = data[index][:activity]
if activity =~ /rest/i && @race_date.saturday? && index == date_list.size - 1
activity = data[index + 1][:activity]
end
cal.event do |e|
e.dtstart = Icalendar::Values::Date.new(date)
e.dtend = Icalendar::Values::Date.new(date)
e.summary = activity
e.ip_class = "PUBLIC"
e.alarm do |a|
a.summary = activity
a.trigger = "-P1DT0H0M0S" end
end
end
cal.publish
cal.to_ical
end
|