Search code examples
ruby-on-railsicalendar

How do I use Icalendar::HasComponents?


Regarding https://github.com/icalendar/icalendar/pull/132: Given that I have a

@cal = Icalendar::Calendar.new

How do I use Icalendar::HasComponents to add X-WR-CALNAME, X-PUBLISHED-TTL and X-WR-CALDESC properties to @cal?

I want to generate these extra properties in my .ics file so that I could add it to Google Calendar and Outlook and allow them to specify

  • X-WR-CALNAME - calendar name
  • X-PUBLISHED-TTL - refresh interval
  • X-WR-CALDESC - calendar description

Solution

  • It's simpler than I thought:

    cal = Icalendar::Calendar.new
    cal.append_custom_property("X-WR-CALNAME","My Calendar") 
    cal.append_custom_property("X-PUBLISHED-TTL","PT1H")  # every hour
    cal.append_custom_property("X-WR-CALDESC","My Desc")
    

    Reference: https://github.com/icalendar/icalendar/blob/master/lib/icalendar/has_properties.rb