calfilter 1.1.3 → 1.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/History.txt CHANGED
@@ -1,3 +1,7 @@
1
+ === 1.1.4 / 2008-05-05
2
+
3
+ * Documentation!
4
+
1
5
  === 1.1.3 / 2008-05-04
2
6
 
3
7
  * Bug fixes:
@@ -5,6 +9,8 @@
5
9
  * Monkey-patched Icalendar to deal with Dates (as opposed to
6
10
  DateTimes) correctly.
7
11
 
12
+ * Monkey-patched Icalendar to preserve UTC on times.
13
+
8
14
  === 1.1.2 / 2008-05-04
9
15
 
10
16
  * Bug fix in calfilter.rb
data/README.txt CHANGED
@@ -12,13 +12,15 @@ various purposes, including:
12
12
  * removing private information from your own calendar before publishing it to others
13
13
  * reformatting a provided calendar to highlight particular information
14
14
 
15
- == FEATURES/PROBLEMS:
15
+ A calfilter script does most of its work using the filter_calendars[link:files/lib/calfilter_rb.html] method.
16
16
 
17
- * require 'calfilter/tripit' to add some methods specific to
17
+ == FEATURES:
18
+
19
+ * require '{calfilter/tripit}[link:files/lib/calfilter/tripit_rb.html]' to add some methods specific to
18
20
  tripit.com calendar feeds.
19
21
 
20
- * require 'calfilter/cgi' to automatically turn your filter into
21
- a CGI script. The CGI object is available as 'CalFilter::CGI'.
22
+ * require '{calfilter/cgi}[link:files/lib/calfilter/cgi_rb.html]' to automatically turn your filter into
23
+ a CGI script. The CGI object is available as <tt>CalFilter::CGI</tt>.
22
24
 
23
25
  == SYNOPSIS:
24
26
 
@@ -43,6 +45,10 @@ calfilter depends on the icalendar gem.
43
45
 
44
46
  sudo gem install calfilter
45
47
 
48
+ == AUTHOR
49
+
50
+ Glenn Vanderburg <glenn@thinkrelevance.com>
51
+
46
52
  == LICENSE:
47
53
 
48
54
  (The MIT License)
data/Rakefile CHANGED
@@ -12,6 +12,9 @@ class Hoe
12
12
  end
13
13
  end
14
14
 
15
+ # Class structure isn't complex enough to make diagrams worthwhile.
16
+ ENV['NODOT'] = "true"
17
+
15
18
  Hoe.new('calfilter', CalFilter::VERSION) do |p|
16
19
  p.rubyforge_name = 'thinkrelevance'
17
20
  p.developer('Glenn Vanderburg', 'glenn@thinkrelevance.com')
data/ToDo.txt CHANGED
@@ -1,5 +1,3 @@
1
- * Greatly improve (i.e., existing) RDocs
2
-
3
1
  * Ensure timezone information is retained
4
2
 
5
3
  * Improved set of TripIt methods
@@ -15,3 +13,6 @@
15
13
 
16
14
  * Similar to the cgi module, it should be easy to require modules
17
15
  to turn a filter into a camping app, a webrick service, etc.
16
+
17
+ * Perhaps have real methods for filter_{events,freebusys,journals,todos}
18
+ to improve the rdocs.
data/lib/calfilter/cgi.rb CHANGED
@@ -1,10 +1,19 @@
1
+ # Turns a calfilter script into a CGI script.
2
+ #
3
+ # Simply require this file at the top of a calfilter script
4
+ # to turn it into a CGI script. The CGI object will be accessible
5
+ # as <tt>CalFilter::CGI</tt>.
6
+ #
7
+ # (This file makes use of CalFilter.output_stream, so please don't
8
+ # set that yourself if using calfilter/cgi.)
9
+
1
10
  require 'calfilter'
2
11
  require 'cgi'
3
12
  require 'stringio'
4
13
 
5
14
  module CalFilter
6
15
 
7
- class CGIWrapper
16
+ class CGIWrapper # :nodoc: all
8
17
  attr_reader :output_stream
9
18
 
10
19
  def initialize(output_stream)
@@ -25,7 +34,7 @@ module CalFilter
25
34
  end
26
35
  end
27
36
 
28
- def self.make_cgi_wrapper
37
+ def self.make_cgi_wrapper # :nodoc:
29
38
  CGIWrapper.new(StringIO.new)
30
39
  end
31
40
 
@@ -1,4 +1,4 @@
1
- class DateTime
1
+ class DateTime # :nodoc: all
2
2
  attr_writer :utc
3
3
 
4
4
  def utc?
@@ -1,18 +1,20 @@
1
- class Icalendar::Parser
2
- def parse_datetime_with_date_check(name, params, value)
3
- if /\d{8}T/ =~ value
4
- dt = parse_datetime_without_date_check(name, params, value)
5
- dt.utc = true if /Z/ =~ value
6
- dt
7
- else
8
- begin
9
- Date.parse(value)
10
- rescue Exception
11
- value
1
+ module Icalendar # :nodoc: all
2
+ class Parser
3
+ def parse_datetime_with_date_check(name, params, value)
4
+ if /\d{8}T/ =~ value
5
+ dt = parse_datetime_without_date_check(name, params, value)
6
+ dt.utc = true if /Z/ =~ value
7
+ dt
8
+ else
9
+ begin
10
+ Date.parse(value)
11
+ rescue Exception
12
+ value
13
+ end
12
14
  end
13
15
  end
14
- end
15
16
 
16
- alias :parse_datetime_without_date_check :parse_datetime
17
- alias :parse_datetime :parse_datetime_with_date_check
18
- end
17
+ alias :parse_datetime_without_date_check :parse_datetime
18
+ alias :parse_datetime :parse_datetime_with_date_check
19
+ end
20
+ end
@@ -1,4 +1,4 @@
1
- class Time
1
+ class Time # :nodoc: all
2
2
  attr_writer :utc
3
3
 
4
4
  def utc?
@@ -1,23 +1,56 @@
1
+ # Mixes methods into CalFilter::ResourceWrapper that help when
2
+ # dealing with calendars from TripIt[http://tripit.com/]. Just
3
+ # require this file at the top of a calfilter script to gain the
4
+ # extra functionality.
5
+
1
6
  require 'calfilter'
2
7
 
3
8
  module CalFilter
4
9
  module TripIt
10
+ # The keys are the $1 strings from description =~ /^\[(.*?)\]/m
5
11
  EVENT_TYPES = {
6
- # The keys are the $1 strings from description =~ /^\[(.*?)\]/m
7
12
  nil => :trip,
8
- 'Flight' => :flight,
13
+ 'Activity' => :activity,
14
+ 'Article' => :article,
9
15
  'Car Rental' => :car,
10
- 'Hotel' => :hotel,
16
+ 'Cruise' => :cruise,
11
17
  'Directions' => :directions,
12
- 'Activity' => :activity
18
+ 'Flight' => :flight,
19
+ 'Hotel' => :hotel,
20
+ 'Map' => :map,
21
+ 'Meeting' => :meeting,
22
+ 'Note' => :note,
23
+ 'Rail' => :rail,
24
+ 'Restaurant' => :restaurant
13
25
  }
14
26
 
27
+ # :call-seq:
28
+ # tripit_type => tripit_type_symbol
29
+ # tripit_type(tripit_type_symbol, ...) => true or false
30
+ #
31
+ # Investigates the type of an event, based on <tt>[<em>Type</em>]</tt> strings in the descriptions used by Trip<b></b>It.
32
+ #
33
+ # TripIt[http://tripit.com/] uses <tt>[<em>Event Type</em>]</tt> strings in its
34
+ # event descriptions to signal what kind of event it is. The known types are the
35
+ # keys used in EVENT_TYPES.
36
+ #
37
+ # This method facilitates querying an event to learn its Trip<b></b>It event type.
38
+ #
39
+ # When called with no arguments, the method will return an event type
40
+ # symbol (one of the values from EVENT_TYPES) to indicate the type of
41
+ # event, or :unknown if an unknown type is encountered (or if the target is
42
+ # some other kind of Icalendar resource, such as a todo).
43
+ #
44
+ # When called with argumetns, those arguments must be event type symbols,
45
+ # and the method will return true if the event is one of those types, and
46
+ # false otherwise (or if the target is not an event).
15
47
  def tripit_type(*args)
16
- return :unknown unless __kind__ == 'event'
17
48
  if args.empty?
49
+ return :unknown unless __kind__ == 'event'
18
50
  description =~ /^\[(.+?)\]/m
19
51
  TripIt::EVENT_TYPES[$1] || :unknown
20
52
  else
53
+ return false unless __kind__ == 'event'
21
54
  args.include?(tripit_type)
22
55
  end
23
56
  end
data/lib/calfilter.rb CHANGED
@@ -4,12 +4,17 @@ $:.unshift(File.dirname(__FILE__))
4
4
  %w{datetime icalendar time}.each{|l| require "calfilter/#{l}_extensions"}
5
5
 
6
6
  module CalFilter
7
- VERSION = '1.1.3'
7
+ VERSION = '1.1.4'
8
8
 
9
+ # The output stream for filtered icalendar output.
10
+ # If this is not nil, filter_calendars will automatically
11
+ # write the filtered calendars to this stream in
12
+ # icalendar format.
9
13
  def self.output_stream
10
14
  @output_stream
11
15
  end
12
16
 
17
+ # Sets output_stream.
13
18
  def self.output_stream=(stream)
14
19
  @output_stream = stream
15
20
  end
@@ -17,46 +22,77 @@ module CalFilter
17
22
  class FilterError < RuntimeError
18
23
  end
19
24
 
25
+ # A filtering wrapper for an
26
+ # Icalendar[http://icalendar.rubyforge.org/]
27
+ # resource object. The wrapped object will be one of:
28
+ #
29
+ # * {Icalendar::Event}[http://icalendar.rubyforge.org/classes/Icalendar/Event.html]
30
+ # * {Icalendar::Freebusy}[http://icalendar.rubyforge.org/classes/Icalendar/Freebusy.html]
31
+ # * {Icalendar::Journal}[http://icalendar.rubyforge.org/classes/Icalendar/Journal.html]
32
+ # * {Icalendar::Todo}[http://icalendar.rubyforge.org/classes/Icalendar/Todo.html]
33
+ #
34
+ # All unrecognized methods are delegated to the underlying
35
+ # resource object, so methods such as #description and #summary
36
+ # work as expected. (The resource object can be accessed directly
37
+ # using the #\__delegate__ method.)
38
+ #
39
+ # In addition to delegating to the resource, ResourceWrapper objects
40
+ # provide a few additional methods:
41
+ #
42
+ # * #\_\_delegate__
43
+ # * #keep
44
+ # * #remove
20
45
  class ResourceWrapper
21
- def initialize(delegate, kind)
46
+ def initialize(delegate, kind) # :nodoc:
22
47
  @delegate = delegate
23
48
  @kind = kind
24
49
  end
25
50
 
51
+ # Provides access to the underlying resource being wrapped.
26
52
  def __delegate__
27
53
  @delegate
28
54
  end
29
55
 
30
- def __action__
56
+ def __action__ # :nodoc:
31
57
  @keep_or_remove || :default
32
58
  end
33
59
 
34
- def __kind__
60
+ def __kind__ # :nodoc:
35
61
  @kind
36
62
  end
37
63
 
64
+ # Marks this resource for removal from the calendar.
65
+ # For a particular kind of resource (e.g., events, todos,
66
+ # journals) in a given calendar, you can call either #remove
67
+ # or #keep on some of the resources, but not both.
38
68
  def remove
39
69
  __flag__ :remove
40
70
  end
41
71
 
72
+ # Marks this resource to be kept in the calendar.
73
+ # If this is called on some resources, all others in the
74
+ # collection will be removed.
75
+ # For a particular kind of resource (e.g., events, todos,
76
+ # journals) in a given calendar, you can call either #remove
77
+ # or #keep on some of the resources, but not both.
42
78
  def keep
43
79
  __flag__ :keep
44
80
  end
45
81
 
46
- def method_missing(symbol, *args, &block)
82
+ def method_missing(symbol, *args, &block) # :nodoc:
47
83
  __delegate__.send(symbol, *args, &block)
48
84
  end
49
85
 
50
86
  protected
51
87
 
52
- def __flag__(sym)
88
+ def __flag__(sym) # :nodoc:
53
89
  other_sym = (sym == :keep ? :remove : :keep)
54
90
  raise FilterError, "Cannot both keep and remove the same #{@kind}", __caller__ if @keep_or_remove == other_sym
55
91
  @keep_or_remove = sym
56
92
  throw :bailout if sym == :remove
57
93
  end
58
94
 
59
- def __caller__
95
+ def __caller__ # :nodoc:
60
96
  f = __FILE__
61
97
  stack = caller
62
98
  stack.each_with_index do |s, i|
@@ -66,13 +102,62 @@ module CalFilter
66
102
 
67
103
  end
68
104
 
105
+ # A filtering wrapper for an
106
+ # {Icalendar::Calendar}[http://icalendar.rubyforge.org/classes/Icalendar/Calendar.html]
107
+ # object.
108
+ #
109
+ # All unrecognized methods are delegated to the underlying
110
+ # Calendar object, so methods such as #events and find_event
111
+ # work as expected. (The Calendar object can be accessed directly
112
+ # using the #\_\_delegate__ method.)
113
+ #
114
+ # In addition to delegating to the Calendar, CalendarWrapper objects
115
+ # provide a few additional methods:
116
+ #
117
+ # * #\_\_delegate__
118
+ # * #keep
119
+ # * #remove
120
+ # * #filter_events
121
+ # * #filter_freebusys
122
+ # * #filter_journals
123
+ # * #filter_todos
124
+ #
125
+ # === Filtering Resource Collections
126
+ #
127
+ # If you want to remove one or more of a calendar's resource collections
128
+ # in their entirety, use #remove (or #keep).
129
+ # But you can also filter the collections themselves:
130
+ #
131
+ # * <b>filter_events</b> <em>{|event| ... }</em>
132
+ # * <b>filter_freebusys</b> <em>{|freebusy| ... }</em>
133
+ # * <b>filter_journals</b> <em>{|journal| ... }</em>
134
+ # * <b>filter_todos</b> <em>{|todo| ... }</em>
135
+ #
136
+ # Each of these methods iterates over all of the elements of
137
+ # the named resource collection, allowing the individual resources
138
+ # to be modified or removed. See ResourceWrapper for the methods
139
+ # available for working with individual resource instances.
69
140
  class CalendarWrapper < ResourceWrapper
70
141
  RESOURCE_TYPES = %w{events freebusys journals todos}
71
142
 
72
- def initialize(calendar)
143
+ def initialize(calendar) # :nodoc:
73
144
  super(calendar, 'calendar')
74
145
  end
75
146
 
147
+ # :call-seq:
148
+ # remove
149
+ # remove(collection_symbol, [collection_symbol, ...])
150
+ #
151
+ # Marks this calendar (or collection of resources in the calendar) for removal.
152
+ #
153
+ # If called with no arguments, removes the entire calendar.
154
+ #
155
+ # Any arguments must be one of <tt>:events</tt>, <tt>:freebusys</tt>,
156
+ # <tt>:journals</tt>, or <tt>:todos</tt>, and
157
+ # the named resource collections will be removed from this calendar.
158
+ #
159
+ # For a given calendar or resource collection, you can call either #remove
160
+ # or #keep, but not both.
76
161
  def remove(*args)
77
162
  if args.empty?
78
163
  super
@@ -81,6 +166,22 @@ module CalFilter
81
166
  end
82
167
  end
83
168
 
169
+ # :call-seq:
170
+ # keep
171
+ # keep(collection_symbol, [collection_symbol, ...])
172
+ #
173
+ # Marks this calendar (or collection of resources in the calendar) to be kept.
174
+ #
175
+ # If called with no arguments, keeps the entire calendar; any calendars
176
+ # not kept will be removed.
177
+ #
178
+ # Any arguments must be one of <tt>:events</tt>, <tt>:freebusys</tt>,
179
+ # <tt>:journals</tt>, or <tt>:todos</tt>, and
180
+ # the named resource collections will be kept in this calendar, and
181
+ # all resource collections not kept will be removed.
182
+ #
183
+ # For a given calendar or resource collection, you can call either #remove
184
+ # or #keep, but not both.
84
185
  def keep(*args)
85
186
  if args.empty?
86
187
  super
@@ -89,7 +190,7 @@ module CalFilter
89
190
  end
90
191
  end
91
192
 
92
- def method_missing(symbol, *args, &block)
193
+ def method_missing(symbol, *args, &block) # :nodoc:
93
194
  if symbol.to_s =~ /^filter_(.*)$/ && RESOURCE_TYPES.include?($1)
94
195
  __filter_resource__($1, *args, &block)
95
196
  else
@@ -121,17 +222,17 @@ module CalFilter
121
222
 
122
223
  end
123
224
 
124
- def self.wrap_calendar(cal)
225
+ def self.wrap_calendar(cal) # :nodoc:
125
226
  CalendarWrapper.new(cal)
126
227
  end
127
228
 
128
- def self.wrap_resource(res, plural_resource_type)
229
+ def self.wrap_resource(res, plural_resource_type) # :nodoc:
129
230
  # This works with the particular resource names in Icalendar:
130
231
  singular_resource_type = plural_resource_type.sub(/s$/, '')
131
232
  ResourceWrapper.new(res, singular_resource_type)
132
233
  end
133
234
 
134
- def self.keep_or_delete_items(items, type, actions)
235
+ def self.keep_or_delete_items(items, type, actions) # :nodoc:
135
236
  if actions.include?(:keep) && actions.include?(:remove)
136
237
  raise CalFilter::FilterError, "Cannot both keep and remove #{type} in the same group.", caller(2)
137
238
  end
@@ -143,6 +244,30 @@ module CalFilter
143
244
 
144
245
  end
145
246
 
247
+ # Filters the calendars found at sources.
248
+ #
249
+ # The sources can be
250
+ #
251
+ # * {Icalendar::Calendar}[http://icalendar.rubyforge.org/classes/Icalendar/Calendar.html]
252
+ # objects,
253
+ # * arrays of those objects (because Icalendar.parse returns arrays
254
+ # of calendars),
255
+ # * URLs pointing to iCalendar[http://en.wikipedia.org/wiki/ICalendar] streams, or
256
+ # * strings containing iCalendar[http://en.wikipedia.org/wiki/ICalendar] streams.
257
+ #
258
+ # The sources are resolved/fetched/parsed into Icalendar::Calendar
259
+ # objects, and passed into the supplied block one by one (as
260
+ # CalendarWrapper objects). The block can filter the calendars,
261
+ # choosing to remove entire calendars or classes of calendar resources,
262
+ # and/or simply modifying those resources as desired. Each calendar object
263
+ # has a #source method that contains associated source parameter from the
264
+ # #filter_calendars call (so that you can recognize different calendars and
265
+ # handle them in distinct ways).
266
+ #
267
+ # The method returns an array of Calendar objects representing the filtered
268
+ # result. If CalFilter::output_stream is not nil, the method will also write
269
+ # the filtered result (as an iCalendar stream) to that output stream before
270
+ # returning.
146
271
  def filter_calendars(*sources, &block)
147
272
  cals = convert_to_icalendars(sources)
148
273
  return cals unless block_given?
@@ -161,19 +286,32 @@ def filter_calendars(*sources, &block)
161
286
  new_cals
162
287
  end
163
288
 
164
- def convert_to_icalendars(sources)
289
+ def convert_to_icalendars(sources) # :nodoc:
165
290
  sources.inject([]){|accum, source| accum += convert_to_icalendar(source)}
166
291
  end
167
292
 
168
- def convert_to_icalendar(source)
169
- case source
170
- when Icalendar::Calendar
171
- [source]
172
- when Array
173
- source
174
- when /^\s*BEGIN:VCALENDAR/m
175
- Icalendar.parse(source)
176
- else
177
- Icalendar.parse(open(source, 'r'))
293
+ def convert_to_icalendar(source) # :nodoc:
294
+ icalendars = case source
295
+ when Icalendar::Calendar
296
+ [source]
297
+ when Array
298
+ source
299
+ when /^\s*BEGIN:VCALENDAR/m
300
+ Icalendar.parse(source)
301
+ else
302
+ Icalendar.parse(open(source, 'r'))
303
+ end
304
+ attach_source_to_icalendars(source, icalendars)
305
+ icalendars
306
+ end
307
+
308
+ def attach_source_to_icalendars(source, icalendars)
309
+ icalendars.each do |icalendar|
310
+ class <<icalendar
311
+ attr_reader :source
312
+ end
313
+ icalendar.instance_variable_set("@source", source)
178
314
  end
315
+
316
+ icalendars
179
317
  end
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: calfilter
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.3
4
+ version: 1.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Glenn Vanderburg
@@ -30,11 +30,12 @@ cert_chain:
30
30
  zrNa6ECLh1VS/pV78rYbAO1ZXsg3l7bY
31
31
  -----END CERTIFICATE-----
32
32
 
33
- date: 2008-05-04 00:00:00 -05:00
33
+ date: 2008-08-06 00:00:00 -05:00
34
34
  default_executable:
35
35
  dependencies:
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: icalendar
38
+ type: :runtime
38
39
  version_requirement:
39
40
  version_requirements: !ruby/object:Gem::Requirement
40
41
  requirements:
@@ -42,7 +43,17 @@ dependencies:
42
43
  - !ruby/object:Gem::Version
43
44
  version: "0"
44
45
  version:
45
- description: "calfilter is a small library to assist in writing filtering programs for icalendar files or streams. It can be used for various purposes, including: * removing items from icalendar feeds that are not interesting to you * removing private information from your own calendar before publishing it to others * reformatting a provided calendar to highlight particular information"
46
+ - !ruby/object:Gem::Dependency
47
+ name: hoe
48
+ type: :development
49
+ version_requirement:
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 1.7.0
55
+ version:
56
+ description: "calfilter is a small library to assist in writing filtering programs for icalendar files or streams. It can be used for various purposes, including: * removing items from icalendar feeds that are not interesting to you * removing private information from your own calendar before publishing it to others * reformatting a provided calendar to highlight particular information A calfilter script does most of its work using the filter_calendars[link:files/lib/calfilter_rb.html] method."
46
57
  email:
47
58
  - glenn@thinkrelevance.com
48
59
  executables: []
@@ -92,7 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
92
103
  requirements: []
93
104
 
94
105
  rubyforge_project: thinkrelevance
95
- rubygems_version: 1.0.1
106
+ rubygems_version: 1.2.0
96
107
  signing_key:
97
108
  specification_version: 2
98
109
  summary: calfilter is a small library to assist in writing filtering programs for icalendar files or streams
metadata.gz.sig CHANGED
Binary file