hiccup 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/hiccup/enumerable.rb +0 -9
- data/lib/hiccup/enumerable/annually_enumerator.rb +15 -14
- data/lib/hiccup/enumerable/never_enumerator.rb +11 -2
- data/lib/hiccup/enumerable/schedule_enumerator.rb +14 -5
- data/lib/hiccup/version.rb +1 -1
- data/test/{weekly_enumerator_test_test.rb → weekly_enumerator_test.rb} +0 -0
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 86859b5552e51f3c4bb91170033f32fb4cdf2c4e
|
4
|
+
data.tar.gz: 8987c7d7ae39b2c83dc109ac7f409f3f22d5d7dc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 68dc0bbf57fba21d13aae5c6786ff679761f690fbc1e6ed05c382d698150e59d4501317f74d84e21fdb8825ef47fed0d362215b4d628d9fcf85f9f15905ebc1e
|
7
|
+
data.tar.gz: eb01df9e219e4a0a38fdd79fd7e5c63fae0a8def9ca1c5b0db745a9e562615566154aa03719178ea847a8345ae8586c8b507e943cc326ab90bd8bdf97ac99272
|
data/lib/hiccup/enumerable.rb
CHANGED
@@ -17,9 +17,6 @@ module Hiccup
|
|
17
17
|
|
18
18
|
|
19
19
|
def occurrences_between(earlier_date, later_date)
|
20
|
-
return [] if ends? && earlier_date > end_date
|
21
|
-
return [] if later_date < start_date
|
22
|
-
|
23
20
|
occurrences = []
|
24
21
|
enum = enumerator.new(self, earlier_date)
|
25
22
|
while (occurrence = enum.next) && (occurrence <= later_date)
|
@@ -31,7 +28,6 @@ module Hiccup
|
|
31
28
|
|
32
29
|
|
33
30
|
def first_occurrence_on_or_after(date)
|
34
|
-
return nil if ends? && date > end_date
|
35
31
|
enumerator.new(self, date).next
|
36
32
|
end
|
37
33
|
|
@@ -43,7 +39,6 @@ module Hiccup
|
|
43
39
|
|
44
40
|
|
45
41
|
def first_occurrence_on_or_before(date)
|
46
|
-
return nil if date < start_date
|
47
42
|
enumerator.new(self, date).prev
|
48
43
|
end
|
49
44
|
|
@@ -67,8 +62,6 @@ module Hiccup
|
|
67
62
|
end
|
68
63
|
|
69
64
|
def n_occurrences_on_or_before(limit, date)
|
70
|
-
return [] if date < start_date
|
71
|
-
|
72
65
|
occurrences = []
|
73
66
|
enum = enumerator.new(self, date)
|
74
67
|
while (occurrence = enum.prev) && occurrences.length < limit
|
@@ -88,8 +81,6 @@ module Hiccup
|
|
88
81
|
end
|
89
82
|
|
90
83
|
def n_occurrences_on_or_after(limit, date)
|
91
|
-
return [] if ends? and date > end_date
|
92
|
-
|
93
84
|
occurrences = []
|
94
85
|
enum = enumerator.new(self, date)
|
95
86
|
while (occurrence = enum.next) && occurrences.length < limit
|
@@ -7,40 +7,42 @@ module Hiccup
|
|
7
7
|
def initialize(*args)
|
8
8
|
super
|
9
9
|
@month, @day = start_date.month, start_date.day
|
10
|
-
|
10
|
+
|
11
|
+
if month == 2 and day == 29
|
12
|
+
def self.current_date
|
13
|
+
Date.new(year, 2, leap_year?(year) ? 29 : 28)
|
14
|
+
end
|
15
|
+
end
|
11
16
|
end
|
12
17
|
|
13
|
-
|
14
|
-
|
18
|
+
attr_reader :month, :day
|
15
19
|
|
16
|
-
|
20
|
+
protected
|
17
21
|
|
18
|
-
|
19
|
-
@february_29
|
20
|
-
end
|
22
|
+
attr_reader :year
|
21
23
|
|
22
24
|
|
23
25
|
|
24
26
|
def advance!
|
25
27
|
@year += skip
|
26
|
-
|
28
|
+
current_date
|
27
29
|
end
|
28
30
|
|
29
31
|
def rewind!
|
30
32
|
@year -= skip
|
31
|
-
|
33
|
+
current_date
|
32
34
|
end
|
33
35
|
|
34
36
|
|
35
37
|
|
36
38
|
def first_occurrence_on_or_after(date)
|
37
39
|
@year = date.year
|
38
|
-
@year +=
|
40
|
+
@year += 1 if (date.month > month) or (date.month == month and date.day > day)
|
39
41
|
|
40
42
|
remainder = (@year - start_date.year) % skip
|
41
43
|
@year += (skip - remainder) if remainder > 0
|
42
44
|
|
43
|
-
|
45
|
+
current_date
|
44
46
|
end
|
45
47
|
|
46
48
|
def first_occurrence_on_or_before(date)
|
@@ -50,13 +52,12 @@ module Hiccup
|
|
50
52
|
remainder = (@year - start_date.year) % skip
|
51
53
|
@year -= remainder if remainder > 0
|
52
54
|
|
53
|
-
|
55
|
+
current_date
|
54
56
|
end
|
55
57
|
|
56
58
|
|
57
59
|
|
58
|
-
def
|
59
|
-
return Date.new(year, month, 28) if february_29? and !leap_year?(year)
|
60
|
+
def current_date
|
60
61
|
Date.new(year, month, day)
|
61
62
|
end
|
62
63
|
|
@@ -5,12 +5,21 @@ module Hiccup
|
|
5
5
|
class NeverEnumerator < ScheduleEnumerator
|
6
6
|
|
7
7
|
|
8
|
+
def next
|
9
|
+
@cursor = @cursor ? nil : first_occurrence_on_or_after(seed_date)
|
10
|
+
end
|
11
|
+
|
12
|
+
def prev
|
13
|
+
@cursor = @cursor ? nil : first_occurrence_on_or_before(seed_date)
|
14
|
+
end
|
15
|
+
|
16
|
+
|
8
17
|
def first_occurrence_on_or_after(date)
|
9
|
-
|
18
|
+
start_date if date <= start_date
|
10
19
|
end
|
11
20
|
|
12
21
|
def first_occurrence_on_or_before(date)
|
13
|
-
date
|
22
|
+
start_date unless date < start_date
|
14
23
|
end
|
15
24
|
|
16
25
|
|
@@ -1,4 +1,3 @@
|
|
1
|
-
|
2
1
|
module Hiccup
|
3
2
|
module Enumerable
|
4
3
|
class ScheduleEnumerator
|
@@ -19,8 +18,6 @@ module Hiccup
|
|
19
18
|
@ends = schedule.ends?
|
20
19
|
@seed_date = seed_date
|
21
20
|
@seed_date = seed_date.to_date if seed_date.respond_to?(:to_date)
|
22
|
-
@seed_date = start_date if (seed_date < start_date)
|
23
|
-
@seed_date = end_date if (ends? && seed_date > end_date)
|
24
21
|
@cursor = nil
|
25
22
|
end
|
26
23
|
|
@@ -29,13 +26,13 @@ module Hiccup
|
|
29
26
|
|
30
27
|
|
31
28
|
def next
|
32
|
-
@cursor = started? ? advance! : first_occurrence_on_or_after(
|
29
|
+
@cursor = started? ? advance! : first_occurrence_on_or_after(seed_start_date)
|
33
30
|
return nil if ends? && @cursor > end_date
|
34
31
|
@cursor
|
35
32
|
end
|
36
33
|
|
37
34
|
def prev
|
38
|
-
@cursor = started? ? rewind! : first_occurrence_on_or_before(
|
35
|
+
@cursor = started? ? rewind! : first_occurrence_on_or_before(seed_end_date)
|
39
36
|
return nil if @cursor < start_date
|
40
37
|
@cursor
|
41
38
|
end
|
@@ -68,6 +65,18 @@ module Hiccup
|
|
68
65
|
|
69
66
|
|
70
67
|
|
68
|
+
def seed_start_date
|
69
|
+
return start_date if (seed_date < start_date)
|
70
|
+
seed_date
|
71
|
+
end
|
72
|
+
|
73
|
+
def seed_end_date
|
74
|
+
return end_date if (ends? && seed_date > end_date)
|
75
|
+
seed_date
|
76
|
+
end
|
77
|
+
|
78
|
+
|
79
|
+
|
71
80
|
# These two methods DO assume that
|
72
81
|
# date is predicted by the given schedule
|
73
82
|
# Subclasses can probably supply more
|
data/lib/hiccup/version.rb
CHANGED
File without changes
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hiccup
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bob Lail
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-10-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -171,7 +171,7 @@ files:
|
|
171
171
|
- test/performance_test.rb
|
172
172
|
- test/test_helper.rb
|
173
173
|
- test/validatable_test.rb
|
174
|
-
- test/
|
174
|
+
- test/weekly_enumerator_test.rb
|
175
175
|
homepage: http://boblail.github.com/hiccup/
|
176
176
|
licenses: []
|
177
177
|
metadata: {}
|
@@ -206,4 +206,4 @@ test_files:
|
|
206
206
|
- test/performance_test.rb
|
207
207
|
- test/test_helper.rb
|
208
208
|
- test/validatable_test.rb
|
209
|
-
- test/
|
209
|
+
- test/weekly_enumerator_test.rb
|