hiccup 0.5.5 → 0.5.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 73e0335450c98c244067b003167f60fdba6539e0
4
- data.tar.gz: cca4f04660cef3cd3e98e9ff8114c80233793bd7
3
+ metadata.gz: 7e951659bd70b7644903b02cf819b518632d0471
4
+ data.tar.gz: 8f34e327a9eebc719cc4729505133bcc38f6b09b
5
5
  SHA512:
6
- metadata.gz: d84ff40e107f34bcb963f3b9be57bd41a5c7642258c982edf63d8b955d5e6065245c94cb4bc384b37eef8d79f493324e2fb3f9e613a3be3ef3de27105ed71aa4
7
- data.tar.gz: e08c0c65406a0c1d4b82fd222e1058b76fa44103bd45bbb632be4b1269459344fc1499a75e60737681601ce27e86f27618462a3298261ed98fd35ba880fee6b4
6
+ metadata.gz: 506065cfc2ac111628892588c57b4cf5c6984d955ccec0a6be6945c74cb9030a8f090f711f12bbc944264ce9cf6900dfa433c6ce1c1544f662b0e9705c740d18
7
+ data.tar.gz: 89844952a547b7f52d991d50add128be4485db4921ba99b7f91f3decbeaddbdefe26901ec68b73945d846becccdfa2d98bcd2b6da58a3c93724f01036af8a42c
@@ -59,34 +59,36 @@ module Hiccup
59
59
 
60
60
 
61
61
 
62
- def n_occurrences_before(limit, date)
63
- n_occurrences_on_or_before(limit, date.to_date - 1)
62
+ def n_occurrences_before(limit, date, options={})
63
+ n_occurrences_on_or_before(limit, date.to_date - 1, options)
64
64
  end
65
65
 
66
- def n_occurrences_on_or_before(limit, date)
66
+ def n_occurrences_on_or_before(limit, date, options={})
67
+ exceptions = options.fetch(:except, [])
67
68
  occurrences = []
68
69
  enum = enumerator.new(self, date)
69
70
  while (occurrence = enum.prev) && occurrences.length < limit
70
- occurrences << occurrence
71
+ occurrences << occurrence unless exceptions.member?(occurrence)
71
72
  end
72
73
  occurrences
73
74
  end
74
75
 
75
76
 
76
77
 
77
- def first_n_occurrences(limit)
78
- n_occurrences_on_or_after(limit, start_date)
78
+ def first_n_occurrences(limit, options={})
79
+ n_occurrences_on_or_after(limit, start_date, options)
79
80
  end
80
81
 
81
- def n_occurrences_after(limit, date)
82
- n_occurrences_on_or_after(limit, date.to_date + 1)
82
+ def n_occurrences_after(limit, date, options={})
83
+ n_occurrences_on_or_after(limit, date.to_date + 1, options)
83
84
  end
84
85
 
85
- def n_occurrences_on_or_after(limit, date)
86
+ def n_occurrences_on_or_after(limit, date, options={})
87
+ exceptions = options.fetch(:except, [])
86
88
  occurrences = []
87
89
  enum = enumerator.new(self, date)
88
90
  while (occurrence = enum.next) && occurrences.length < limit
89
- occurrences << occurrence
91
+ occurrences << occurrence unless exceptions.member?(occurrence)
90
92
  end
91
93
  occurrences
92
94
  end
@@ -1,3 +1,3 @@
1
1
  module Hiccup
2
- VERSION = "0.5.5"
2
+ VERSION = "0.5.6"
3
3
  end
@@ -3,6 +3,8 @@ require "test_helper"
3
3
 
4
4
  class EnumerableTest < ActiveSupport::TestCase
5
5
  include Hiccup
6
+
7
+ attr_reader :schedule
6
8
 
7
9
 
8
10
 
@@ -129,35 +131,78 @@ class EnumerableTest < ActiveSupport::TestCase
129
131
  assert schedule.contains?(expected_date)
130
132
  end
131
133
 
134
+
132
135
 
133
-
134
- def test_n_occurrences_before
135
- schedule = Schedule.new({
136
- :kind => :weekly,
137
- :weekly_pattern => %w{Monday Wednesday Friday},
138
- :start_date => Date.new(2009,3,15),
139
- :ends => true,
140
- :end_date => Date.new(2009,11,30)})
141
- dates = schedule.n_occurrences_before(10, Date.new(2009, 10, 31)).map { |date| date.strftime("%Y-%m-%d") }
136
+ context "#n_occurrences_before" do
137
+ setup do
138
+ @schedule = Schedule.new({
139
+ :kind => :weekly,
140
+ :weekly_pattern => %w{Monday Wednesday Friday},
141
+ :start_date => Date.new(2009,3,15),
142
+ :ends => true,
143
+ :end_date => Date.new(2009,11,30)})
144
+ end
145
+
146
+ should "return the right dates" do
147
+ dates = schedule.n_occurrences_before(10, Date.new(2009, 10, 31)).map { |date| date.strftime("%Y-%m-%d") }
148
+ expected_dates = ["2009-10-30", "2009-10-28", "2009-10-26",
149
+ "2009-10-23", "2009-10-21", "2009-10-19",
150
+ "2009-10-16", "2009-10-14", "2009-10-12",
151
+ "2009-10-09" ]
152
+ assert_equal expected_dates, dates, "Expected the dates for the correct occurrences"
153
+ end
142
154
 
143
- expected_dates = ["2009-10-30", "2009-10-28", "2009-10-26",
144
- "2009-10-23", "2009-10-21", "2009-10-19",
145
- "2009-10-16", "2009-10-14", "2009-10-12",
146
- "2009-10-09" ]
147
- assert_equal expected_dates, dates
155
+ should "return a shorter array if no events exist before the given date" do
156
+ dates = schedule.n_occurrences_before(10, Date.new(2009, 3, 20)).map { |date| date.strftime("%Y-%m-%d") }
157
+
158
+ expected_dates = ["2009-03-18", "2009-03-16"]
159
+ assert_equal expected_dates, dates, "Expected the dates for the correct occurrences"
160
+ end
161
+
162
+ context "with blacklisted dates" do
163
+ should "still return the correct number of recurrences" do
164
+ dates = schedule.n_occurrences_before(3, Date.new(2009, 10, 31), except: [Date.new(2009, 10, 28)]).map { |date| date.strftime("%Y-%m-%d") }
165
+ assert_equal 3, dates.count, "Expected the same number of recurrences when blacklisting a date"
166
+ refute dates.member?("2009-10-28"), "Expected the blacklisted date to be omitted"
167
+ assert dates.member?("2009-10-23"), "Expected the next matching date to be included"
168
+ end
169
+ end
148
170
  end
149
-
150
- test "n_occurrences_before should return a shorter array if no events exist before the given date" do
151
- schedule = Schedule.new({
152
- :kind => :weekly,
153
- :weekly_pattern => %w{Monday Wednesday Friday},
154
- :start_date => Date.new(2009,3,15),
155
- :ends => true,
156
- :end_date => Date.new(2009,11,30)})
157
- dates = schedule.n_occurrences_before(10, Date.new(2009, 3, 20)).map { |date| date.strftime("%Y-%m-%d") }
158
-
159
- expected_dates = ["2009-03-18", "2009-03-16"]
160
- assert_equal expected_dates, dates
171
+
172
+ context "#n_occurrences_after" do
173
+ setup do
174
+ @schedule = Schedule.new({
175
+ :kind => :weekly,
176
+ :weekly_pattern => %w{Monday Wednesday Friday},
177
+ :start_date => Date.new(2009,3,15),
178
+ :ends => true,
179
+ :end_date => Date.new(2009,11,30)})
180
+ end
181
+
182
+ should "return the right dates" do
183
+ dates = schedule.n_occurrences_after(10, Date.new(2009, 10, 31)).map { |date| date.strftime("%Y-%m-%d") }
184
+ expected_dates = ["2009-11-02", "2009-11-04", "2009-11-06",
185
+ "2009-11-09", "2009-11-11", "2009-11-13",
186
+ "2009-11-16", "2009-11-18", "2009-11-20",
187
+ "2009-11-23"]
188
+ assert_equal expected_dates, dates, "Expected the dates for the correct occurrences"
189
+ end
190
+
191
+ should "return a shorter array if no events exist before the given date" do
192
+ dates = schedule.n_occurrences_after(10, Date.new(2009, 11, 25)).map { |date| date.strftime("%Y-%m-%d") }
193
+
194
+ expected_dates = ["2009-11-27", "2009-11-30"]
195
+ assert_equal expected_dates, dates, "Expected the dates for the correct occurrences"
196
+ end
197
+
198
+ context "with blacklisted dates" do
199
+ should "still return the current number of recurrences" do
200
+ dates = schedule.n_occurrences_after(3, Date.new(2009, 10, 31), except: [Date.new(2009, 11, 4)]).map { |date| date.strftime("%Y-%m-%d") }
201
+ assert_equal 3, dates.count, "Expected the same number of recurrences when blacklisting a date"
202
+ refute dates.member?("2009-11-04"), "Expected the blacklisted date to be omitted"
203
+ assert dates.member?("2009-11-09"), "Expected the next matching date to be included"
204
+ end
205
+ end
161
206
  end
162
207
 
163
208
 
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.5
4
+ version: 0.5.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bob Lail
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-26 00:00:00.000000000 Z
11
+ date: 2014-03-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport