EdvardM-recurrence 0.1.14 → 0.1.15
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/spec/recurrence_spec.rb +21 -0
- metadata +1 -1
- data/README +0 -70
data/spec/recurrence_spec.rb
CHANGED
@@ -24,6 +24,27 @@ describe Recurrence do
|
|
24
24
|
Recurrence.new(:epoch, :every => :day).start_date.should == Date.new(1970, 1, 1)
|
25
25
|
end
|
26
26
|
end
|
27
|
+
|
28
|
+
describe("comparison") do
|
29
|
+
it "should be equal to another if until, start_date and recurrence types match" do
|
30
|
+
r1 = Recurrence.new('2008-08-27', :every_second => :week, :until => '2008-10-1')
|
31
|
+
r2 = Recurrence.new('2008-08-27', :every_second => :week, :until => '2008-10-1')
|
32
|
+
(r1 == r2).should be_true
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should not be equal even if only until differs" do
|
36
|
+
r1 = Recurrence.new('2008-08-27', :every_second => :week, :until => '2008-10-2')
|
37
|
+
r2 = Recurrence.new('2008-08-27', :every_second => :week, :until => '2008-10-1')
|
38
|
+
(r1 == r2).should be_false
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
describe 'AR integration' do
|
44
|
+
it "should be saveable" do
|
45
|
+
r1 = Recurrence.new('2008-08-27', :every_second => :week, :until => '2008-10-1')
|
46
|
+
end
|
47
|
+
end
|
27
48
|
|
28
49
|
it "should return initialization time" do
|
29
50
|
r = Recurrence.new([2008, 8, 27], :every => :day)
|
metadata
CHANGED
data/README
DELETED
@@ -1,70 +0,0 @@
|
|
1
|
-
= Recurrence
|
2
|
-
|
3
|
-
== Overview
|
4
|
-
|
5
|
-
Recurrence provides a simple class for handling recurring, time-associated objects. The goal is to create a general-purpose,
|
6
|
-
loosely coupled class library to provide common functionality for events occurring at predetermined intervals.
|
7
|
-
|
8
|
-
Short example:
|
9
|
-
|
10
|
-
require 'recurrence'
|
11
|
-
|
12
|
-
first_of_june = [2008, 6, 1]
|
13
|
-
r = Recurrence.new(first_of_june, :every_other => :week, :until => '2010-06-01')
|
14
|
-
|
15
|
-
my_cal = MyCalendar.new_default
|
16
|
-
my_cal.each_day { |date|
|
17
|
-
time = Time.parse(date) # assuming date can be parsed with Time.parse
|
18
|
-
puts 'Yay! today is the day!' if r.recurs_on?(time)
|
19
|
-
}
|
20
|
-
|
21
|
-
== Set-like operations
|
22
|
-
|
23
|
-
Real power of Recurrence lies in it's support for set-like operations +join+, +intersect+, +diff+ and +complement+. For example,
|
24
|
-
given the start date of 2008-06-01, recur something every thursday and friday:
|
25
|
-
|
26
|
-
require 'recurrence'
|
27
|
-
|
28
|
-
start_date = '2008-06-01'
|
29
|
-
r1 = Recurrence.new(start_date, :every => :thursday)
|
30
|
-
r2 = Recurrence.new(start_date, :every => :friday)
|
31
|
-
r = r1.join(r2)
|
32
|
-
|
33
|
-
Another example, a tad contrived perhaps:
|
34
|
-
|
35
|
-
# Recur something every friday, except if it is last friday of the month:
|
36
|
-
|
37
|
-
dow = :friday
|
38
|
-
r1 = Recurrence.new(:epoch, :every => dow)
|
39
|
-
r2 = Recurrence.new(:epoch, :every_last => dow, :of => :month)
|
40
|
-
|
41
|
-
r = r1.diff(r2)
|
42
|
-
|
43
|
-
Nested set-like operations are also possible. So, for arbitrary recurrences a and b and any time t, the following should always apply:
|
44
|
-
|
45
|
-
r1 = (a.join(b)).complement
|
46
|
-
r2 = (a.complement).intersect(b.complement)
|
47
|
-
|
48
|
-
r1.recurs_on?(t) == r2.recurs_on?(t) # De Morgan's law - complement of a union is the same as intersection of the complements
|
49
|
-
|
50
|
-
See RecurrenceBase::SetOperations for more.
|
51
|
-
|
52
|
-
== Installation
|
53
|
-
|
54
|
-
Enter
|
55
|
-
|
56
|
-
rake gem
|
57
|
-
|
58
|
-
on the command line in the same directory as this README file, it should produce the gem under the pkg directory.
|
59
|
-
Then you should be able to say
|
60
|
-
|
61
|
-
sudo gem install pkg/recurrence*.gem
|
62
|
-
|
63
|
-
to install the gem to your local system.
|
64
|
-
|
65
|
-
KTHXBAI
|
66
|
-
|
67
|
-
== License
|
68
|
-
|
69
|
-
MIT (see MIT-LICENSE)
|
70
|
-
|