Sha256: 7d2ef90f956fcd01d4948a19bfb88ccccede0b2b26be5bb4025ea035c3c36e0b
Contents?: true
Size: 1.4 KB
Versions: 1
Compression:
Stored size: 1.4 KB
Contents
require "run_ical/version" Dir[File.expand_path("../run_ical/data/*.rb", __FILE__)].each do |file| require file end require "icalendar" module RunIcal class Generator def self.generate(race_date:, program:) unless RunIcal::Data.constants.include?(program.to_sym) raise ArgumentError, "#{program} is unsupported" end program = program.to_sym new(race_date: race_date, program: program).generate end def initialize(race_date:, program:) @race_date = race_date @program = RunIcal::Data.const_get(program) end 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.sunday? ? 1 : 2 start_date = @race_date - (data.size - start_date_padding).days (start_date..@race_date).to_a.each.with_index do |date, index| activity = data[index][:activity] 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" # 1 day before end end end cal.publish cal.to_ical end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
run_ical-0.4.1 | lib/run_ical.rb |