Class: IcsEventBuilder
- Inherits:
-
Object
- Object
- IcsEventBuilder
- Defined in:
- app/services/ics_event_builder.rb
Overview
Builds a single-event RFC-5545 iCalendar document.
Consolidates the calendar scaffolding — the timezone block,
Icalendar::Calendar setup and event construction — shared by
SchedulerBookingMailer and SupportCase. Wraps the icalendar gem so
callers only describe the event, not the iCalendar object graph.
Instance Method Summary collapse
-
#calendar ⇒ Icalendar::Calendar
The assembled calendar.
-
#initialize(tzid:, starts_at:, ends_at:, summary:, description: nil, uid: nil, sequence: nil, location: nil, organizer: nil, attendees: [], ip_method: nil, cancelled: false) ⇒ IcsEventBuilder
constructor
A new instance of IcsEventBuilder.
-
#to_ical ⇒ String
The serialized
.icspayload.
Constructor Details
#initialize(tzid:, starts_at:, ends_at:, summary:, description: nil, uid: nil, sequence: nil, location: nil, organizer: nil, attendees: [], ip_method: nil, cancelled: false) ⇒ IcsEventBuilder
Returns a new instance of IcsEventBuilder.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'app/services/ics_event_builder.rb', line 30 def initialize(tzid:, starts_at:, ends_at:, summary:, description: nil, uid: nil, sequence: nil, location: nil, organizer: nil, attendees: [], ip_method: nil, cancelled: false) @tzid = tzid @starts_at = starts_at @ends_at = ends_at @summary = summary @description = description @uid = uid @sequence = sequence @location = location @organizer = organizer @attendees = Array(attendees) @ip_method = ip_method @cancelled = cancelled end |
Instance Method Details
#calendar ⇒ Icalendar::Calendar
Returns the assembled calendar.
48 49 50 51 52 53 54 55 56 57 |
# File 'app/services/ics_event_builder.rb', line 48 def calendar require 'icalendar' require 'icalendar/tzinfo' cal = Icalendar::Calendar.new cal.ip_method = @ip_method.to_s.upcase if @ip_method cal.add_timezone(TZInfo::Timezone.get(@tzid).ical_timezone(@starts_at)) cal.event { |event| populate(event) } cal end |
#to_ical ⇒ String
Returns the serialized .ics payload.
60 61 62 |
# File 'app/services/ics_event_builder.rb', line 60 def to_ical calendar.to_ical end |