ice_cube 0.6.3 → 0.6.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.
@@ -27,13 +27,23 @@ module IceCube
27
27
 
28
28
  # Break after the first occurrence after now
29
29
  def next_occurrence(from)
30
- found_one = false
31
- find_occurrences do |roc|
30
+ next_occurrences(1, from).first
31
+ end
32
+
33
+ # Break after the first n occurrences after now
34
+ def next_occurrences(n, from)
35
+ found_all = false
36
+ num_found = 0
37
+ nexts = find_occurrences do |roc|
32
38
  find = roc > from
33
- success = found_one
34
- found_one = find
39
+ num_found += 1 if find
40
+ success = found_all
41
+ found_all = num_found == n
35
42
  success
36
43
  end
44
+ #Since the above returns all up to and including the next N that were requested, we need
45
+ #to grab the last n, making sure to prune out ones that were actually before the from time
46
+ nexts.last(n).select{|occurrence| occurrence > from}
37
47
  end
38
48
 
39
49
  def first(n)
@@ -135,8 +135,14 @@ module IceCube
135
135
 
136
136
  # Find next scheduled occurrence
137
137
  def next_occurrence(from = Time.now)
138
- nexts = find_occurrences { |head| head.next_occurrence(from) }
139
- nexts.empty? ? nil : (nexts.last if nexts.last > from)
138
+ next_occurrences(1, from).first
139
+ end
140
+
141
+ def next_occurrences(n, from = Time.now)
142
+ nexts = find_occurrences { |head| head.next_occurrences(n, from) }
143
+ #Grabs the first n occurrences after the from date, remembering that there is still a
144
+ #possibility that recurrence dates before the from time could be in the array
145
+ nexts.select{|occurrence| occurrence > from}.first(n)
140
146
  end
141
147
 
142
148
  # Retrieve the first (n) occurrences of the schedule. May return less than
@@ -1,5 +1,5 @@
1
1
  module IceCube
2
2
 
3
- VERSION = '0.6.3'
3
+ VERSION = '0.6.4'
4
4
 
5
5
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ice_cube
3
3
  version: !ruby/object:Gem::Version
4
- hash: 1
4
+ hash: 15
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 6
9
- - 3
10
- version: 0.6.3
9
+ - 4
10
+ version: 0.6.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - John Crepezzi
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-10-21 00:00:00 -04:00
18
+ date: 2010-11-16 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency