calfilter 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,11 @@
1
+ === 1.1.0 / 2008-05-03
2
+
3
+ * 1 major enhancement
4
+
5
+ * Collapsed filter_calendars, filter_icalendars, and
6
+ filter_calendars_at into one smarter filter_calendars
7
+ method.
8
+
1
9
  === 1.0.0 / 2008-05-02
2
10
 
3
11
  * 1 major enhancement
data/README.txt CHANGED
@@ -24,7 +24,7 @@ various purposes, including:
24
24
 
25
25
  require 'calfilter'
26
26
 
27
- cals = filter_calendars_at('some_url') do |cal|
27
+ cals = filter_calendars('some_url') do |cal|
28
28
  cal.keep(:events) # not journals, todos, or freebusys
29
29
 
30
30
  cal.filter_events do |evt|
data/example.rb CHANGED
@@ -1,11 +1,14 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ # Would be accessed like this:
4
+ # http://example.com/cgi_bin/example.rb?http://example.com/unfiltered_calendar.ics
5
+
3
6
  require 'rubygems'
4
7
  gem 'calfilter'
5
8
  require 'calfilter'
6
9
  require 'calfilter/cgi'
7
10
 
8
- filter_calendars_at(CalFilter::CGI.query_string}) do |cal|
11
+ filter_calendars(CalFilter::CGI.query_string}) do |cal|
9
12
  cal.keep(:events) # drop todos, journals, etc.
10
13
 
11
14
  cal.filter_events do |evt|
data/lib/calfilter.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  %w{rubygems icalendar date open-uri}.each{|l| require l}
2
2
 
3
3
  module CalFilter
4
- VERSION = '1.0.0'
4
+ VERSION = '1.1.0'
5
5
 
6
6
  def self.output_stream
7
7
  @output_stream
@@ -140,15 +140,8 @@ module CalFilter
140
140
 
141
141
  end
142
142
 
143
- def filter_calendars_at(url, &block)
144
- filter_calendars(open(url, 'r'), &block)
145
- end
146
-
147
- def filter_calendars(ics_data, &block)
148
- filter_icalendars(Icalendar.parse(ics_data), &block)
149
- end
150
-
151
- def filter_icalendars(cals)
143
+ def filter_calendars(*sources, &block)
144
+ cals = convert_to_icalendars(sources)
152
145
  return cals unless block_given?
153
146
  actions = cals.map do |cal|
154
147
  wrapper = CalFilter.wrap_calendar(cal)
@@ -163,4 +156,21 @@ def filter_icalendars(cals)
163
156
  new_cals.each{|cal| os.puts cal.to_ical}
164
157
  end
165
158
  new_cals
166
- end
159
+ end
160
+
161
+ def convert_to_icalendars(sources)
162
+ sources.map{|source| convert_to_icalendar(source)}.flatten
163
+ end
164
+
165
+ def convert_to_icalendar(source)
166
+ case source
167
+ when Icalendar::Calendar
168
+ [source]
169
+ when Array
170
+ source
171
+ when /^\s*BEGIN:VCALENDAR/m
172
+ Icalendar.parse(source)
173
+ else
174
+ Icalendar.parse(open(source, 'r'))
175
+ end
176
+ end
@@ -5,24 +5,41 @@ require 'mocha'
5
5
  require 'calfilter'
6
6
 
7
7
  describe "filtering calendars" do
8
+ it "should fetch urls and parse them" do
9
+ url = 'http://example.com/'
10
+ ics = 'ics data'
11
+ self.expects(:open).with('http://example.com/', 'r').returns(ics)
12
+ Icalendar.expects(:parse).with(ics).returns([])
13
+ filter_calendars("http://example.com/")
14
+ end
15
+
16
+ it "should parse ics data" do
17
+ ics = %{
18
+
19
+ BEGIN:VCALENDAR
20
+ }
21
+ Icalendar.expects(:parse).with(ics).returns([])
22
+ filter_calendars(ics)
23
+ end
24
+
8
25
  it "should pass things straight through" do
9
26
  expected_cals = [1, 2, 3]
10
- actual_cals = filter_icalendars(expected_cals.dup)
27
+ actual_cals = filter_calendars(expected_cals.dup)
11
28
  assert_equal expected_cals.size, actual_cals.size
12
29
  end
13
30
 
14
31
  it "should delete a calendar when told" do
15
- cals = filter_icalendars([1, 2, 3]){|cal| cal.remove if cal.__delegate__ == 2}
32
+ cals = filter_calendars([1, 2, 3]){|cal| cal.remove if cal.__delegate__ == 2}
16
33
  assert_equal [1, 3], cals
17
34
  end
18
35
 
19
36
  it "should keep a calendar when told" do
20
- cals = filter_icalendars([1, 2, 3]){|cal| cal.keep if cal.__delegate__ == 2}
37
+ cals = filter_calendars([1, 2, 3]){|cal| cal.keep if cal.__delegate__ == 2}
21
38
  assert_equal [2], cals
22
39
  end
23
40
 
24
41
  it "should delete parts of a calendar when told" do
25
- cals = filter_icalendars(%w{1 2 3}) do |cal|
42
+ cals = filter_calendars(%w{1 2 3}) do |cal|
26
43
  events = mock(:clear => nil)
27
44
  cal.__delegate__.stubs(:events).returns(events)
28
45
  cal.remove(:events)
@@ -30,7 +47,7 @@ describe "filtering calendars" do
30
47
  end
31
48
 
32
49
  it "should keep parts of a calendar when told" do
33
- cals = filter_icalendars(%w{1 2 3}) do |cal|
50
+ cals = filter_calendars(%w{1 2 3}) do |cal|
34
51
  events = mock(:clear => nil)
35
52
  cal.__delegate__.stubs(:events).returns(events)
36
53
  cal.keep(:freebusys, :journals, :todos)
@@ -39,13 +56,13 @@ describe "filtering calendars" do
39
56
 
40
57
  it "should complain if we both keep and remove a calendar" do
41
58
  assert_raise(CalFilter::FilterError) do
42
- cals = filter_icalendars([1]){|cal| cal.keep; cal.remove}
59
+ cals = filter_calendars([1]){|cal| cal.keep; cal.remove}
43
60
  end
44
61
  end
45
62
 
46
63
  it "should complain if we keep one calendar and remove another" do
47
64
  assert_raises(CalFilter::FilterError) do
48
- cals = filter_icalendars([1, 2, 3]) do |cal|
65
+ cals = filter_calendars([1, 2, 3]) do |cal|
49
66
  case cal.__delegate__
50
67
  when 1: cal.keep;
51
68
  when 2: cal.remove;
@@ -56,7 +73,7 @@ describe "filtering calendars" do
56
73
 
57
74
  it "should delegate unknown methods to the Calendar objects" do
58
75
  results = []
59
- cals = filter_icalendars([0, 1]){|cal| results << cal.zero?}
76
+ cals = filter_calendars([0, 1]){|cal| results << cal.zero?}
60
77
  assert_equal [true, false], results
61
78
  end
62
79
 
@@ -82,7 +99,7 @@ describe "filtering resources" do
82
99
  end
83
100
 
84
101
  xit "should leave resources alone if no block specified" do
85
- filter_icalendars([@cal]) do |cal|
102
+ filter_calendars([@cal]) do |cal|
86
103
  cal.__delegate__.expects(:events).returns(@cal.events)
87
104
  cal.filter_events
88
105
  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.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Glenn Vanderburg
@@ -30,7 +30,7 @@ cert_chain:
30
30
  zrNa6ECLh1VS/pV78rYbAO1ZXsg3l7bY
31
31
  -----END CERTIFICATE-----
32
32
 
33
- date: 2008-05-02 00:00:00 -05:00
33
+ date: 2008-05-03 00:00:00 -05:00
34
34
  default_executable:
35
35
  dependencies:
36
36
  - !ruby/object:Gem::Dependency
metadata.gz.sig CHANGED
Binary file