Class: CalInvite::Providers::Ical

Inherits:
BaseProvider show all
Defined in:
lib/cal_invite/providers/ical.rb

Overview

iCalendar format provider for generating ICS (iCalendar) content. This provider generates calendar content following the iCalendar specification (RFC 5545). It supports single events, all-day events, and multi-day sessions with proper timezone handling.

Examples:

Creating a regular event

event = CalInvite::Event.new(
  title: "Team Meeting",
  start_time: Time.now,
  end_time: Time.now + 3600,
  timezone: 'America/New_York'
)
ical = CalInvite::Providers::Ical.new(event)
ics_content = ical.generate

Creating a multi-day event

event = CalInvite::Event.new(
  title: "Conference",
  multi_day_sessions: [
    { start_time: Time.now, end_time: Time.now + 3600 },
    { start_time: Time.now + 86400, end_time: Time.now + 90000 }
  ]
)
ics_content = CalInvite::Providers::Ical.new(event).generate

Instance Attribute Summary

Attributes inherited from BaseProvider

#event, #method

Instance Method Summary collapse

Methods inherited from BaseProvider

#initialize

Constructor Details

This class inherits a constructor from BaseProvider

Instance Method Details

#generateString

Generates an iCalendar format string containing the event details. Includes proper calendar headers, timezone information (if needed), and one or more event blocks.

Returns:

  • (String)

    The complete iCalendar format content



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/cal_invite/providers/ical.rb', line 35

def generate
  [
    "BEGIN:VCALENDAR",
    "VERSION:2.0",
    "PRODID:-//CalInvite//Ruby//EN",
    "CALSCALE:GREGORIAN",
    "METHOD:#{method_value}",
    (event.calendar_name ? "X-WR-CALNAME:#{escape_text(event.calendar_name)}" : nil),
    generate_timezone,
    generate_events,
    "END:VCALENDAR"
  ].compact.join("\r\n")
end