Class: CalFilter::CalendarWrapper

Inherits:
ResourceWrapper show all
Defined in:
lib/calfilter.rb

Overview

A filtering wrapper for an Icalendar::Calendar object.

All unrecognized methods are delegated to the underlying Calendar object, so methods such as #events and find_event work as expected. (The Calendar object can be accessed directly using the #_delegate_ method.)

In addition to delegating to the Calendar, CalendarWrapper objects provide a few additional methods:

  • #_delegate_

  • #keep

  • #remove

  • #filter_events

  • #filter_freebusys

  • #filter_journals

  • #filter_todos

Filtering Resource Collections

If you want to remove one or more of a calendar’s resource collections in their entirety, use #remove (or #keep).

But you can also filter the collections themselves:

  • filter_events {|event| … }

  • filter_freebusys {|freebusy| … }

  • filter_journals {|journal| … }

  • filter_todos {|todo| … }

Each of these methods iterates over all of the elements of the named resource collection, allowing the individual resources to be modified or removed. See ResourceWrapper for the methods available for working with individual resource instances.

Constant Summary collapse

RESOURCE_TYPES =
%w{events freebusys journals todos}

Constants included from TripIt

TripIt::EVENT_TYPES

Instance Method Summary collapse

Methods inherited from ResourceWrapper

#__action__, #__delegate__, #__kind__

Methods included from TripIt

#tripit_type

Constructor Details

#initialize(calendar) ⇒ CalendarWrapper

:nodoc:



142
143
144
# File 'lib/calfilter.rb', line 142

def initialize(calendar)   # :nodoc:
  super(calendar, 'calendar')
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(symbol, *args, &block) ⇒ Object

:nodoc:



192
193
194
195
196
197
198
# File 'lib/calfilter.rb', line 192

def method_missing(symbol, *args, &block)  # :nodoc:
  if symbol.to_s =~ /^filter_(.*)$/ && RESOURCE_TYPES.include?($1)
    __filter_resource__($1, *args, &block)
  else
    super(symbol, *args, &block)
  end
end

Instance Method Details

#keep(*args) ⇒ Object

:call-seq:

keep
keep(collection_symbol, [collection_symbol, ...])

Marks this calendar (or collection of resources in the calendar) to be kept.

If called with no arguments, keeps the entire calendar; any calendars not kept will be removed.

Any arguments must be one of :events, :freebusys, :journals, or :todos, and the named resource collections will be kept in this calendar, and all resource collections not kept will be removed.

For a given calendar or resource collection, you can call either #remove or #keep, but not both.



184
185
186
187
188
189
190
# File 'lib/calfilter.rb', line 184

def keep(*args)
  if args.empty?
    super
  else
    __remove_elements__ :keep, RESOURCE_TYPES.map{|t|t.to_sym} - args
  end
end

#remove(*args) ⇒ Object

:call-seq:

remove
remove(collection_symbol, [collection_symbol, ...])

Marks this calendar (or collection of resources in the calendar) for removal.

If called with no arguments, removes the entire calendar.

Any arguments must be one of :events, :freebusys, :journals, or :todos, and the named resource collections will be removed from this calendar.

For a given calendar or resource collection, you can call either #remove or #keep, but not both.



160
161
162
163
164
165
166
# File 'lib/calfilter.rb', line 160

def remove(*args)
  if args.empty?
    super
  else
    __remove_elements__ :remove, args
  end
end