Top Level Namespace
Defined Under Namespace
Modules: CalFilter, Icalendar Classes: DateTime, Time
Instance Method Summary collapse
- #attach_source_to_icalendars(source, icalendars) ⇒ Object
-
#convert_to_icalendar(source) ⇒ Object
:nodoc:.
-
#convert_to_icalendars(sources) ⇒ Object
:nodoc:.
-
#filter_calendars(*sources, &block) ⇒ Object
Filters the calendars found at sources.
Instance Method Details
#attach_source_to_icalendars(source, icalendars) ⇒ Object
307 308 309 310 311 312 313 314 315 316 |
# File 'lib/calfilter.rb', line 307 def attach_source_to_icalendars(source, icalendars) icalendars.each do |icalendar| class <<icalendar attr_reader :source end icalendar.instance_variable_set("@source", source) end icalendars end |
#convert_to_icalendar(source) ⇒ Object
:nodoc:
292 293 294 295 296 297 298 299 300 301 302 303 304 305 |
# File 'lib/calfilter.rb', line 292 def convert_to_icalendar(source) # :nodoc: icalendars = case source when Icalendar::Calendar [source] when Array source when /^\s*BEGIN:VCALENDAR/m Icalendar.parse(source) else Icalendar.parse(open(source, 'r')) end attach_source_to_icalendars(source, icalendars) icalendars end |
#convert_to_icalendars(sources) ⇒ Object
:nodoc:
288 289 290 |
# File 'lib/calfilter.rb', line 288 def convert_to_icalendars(sources) # :nodoc: sources.inject([]){|accum, source| accum += convert_to_icalendar(source)} end |
#filter_calendars(*sources, &block) ⇒ Object
Filters the calendars found at sources.
The sources can be
-
Icalendar::Calendar objects,
-
arrays of those objects (because Icalendar.parse returns arrays of calendars),
-
URLs pointing to iCalendar streams, or
-
strings containing iCalendar streams.
The sources are resolved/fetched/parsed into Icalendar::Calendar objects, and passed into the supplied block one by one (as CalendarWrapper objects). The block can filter the calendars, choosing to remove entire calendars or classes of calendar resources, and/or simply modifying those resources as desired. Each calendar object has a #source method that contains associated source parameter from the #filter_calendars call (so that you can recognize different calendars and handle them in distinct ways).
The method returns an array of Calendar objects representing the filtered result. If CalFilter::output_stream is not nil, the method will also write the filtered result (as an iCalendar stream) to that output stream before returning.
270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 |
# File 'lib/calfilter.rb', line 270 def filter_calendars(*sources, &block) cals = convert_to_icalendars(sources) return cals unless block_given? actions = cals.map do |cal| wrapper = CalFilter.wrap_calendar(cal) catch(:bailout) do yield wrapper end wrapper.__action__ end new_cals = CalFilter::keep_or_delete_items(cals, 'calendars', actions) os = CalFilter.output_stream unless os.nil? new_cals.each{|cal| os.puts cal.to_ical} end new_cals end |