nickel 0.0.6 → 0.1.0

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.
@@ -0,0 +1,14 @@
1
+ require "spec_helper"
2
+ require_relative "../../../lib/nickel/nlp"
3
+
4
+ module Nickel
5
+ describe NLP do
6
+ describe "#new" do
7
+ it "raises an error if the current time argument is not a datetime or time object" do
8
+ expect{
9
+ NLP.new "lunch 3 days from now", Date.new(2009,05,28)
10
+ }.to raise_error("You must pass in a ruby DateTime or Time class object")
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,40 @@
1
+ require "spec_helper"
2
+ require_relative "../../../lib/nickel/occurrence"
3
+ require_relative "../../../lib/nickel/zdate"
4
+
5
+ module Nickel
6
+ describe Occurrence do
7
+ describe "#==" do
8
+ let(:occ) { Occurrence.new(type: :daily, start_date: ZDate.new("20140128")) }
9
+
10
+ it "is true when comparing to itself" do
11
+ expect(occ).to eq occ
12
+ end
13
+
14
+ it "is false when comparing to nil" do
15
+ expect(occ).to_not eq nil
16
+ end
17
+
18
+ it "is false when comparing to a string" do
19
+ expect(occ).to_not eq "occ"
20
+ end
21
+
22
+ it "is false when comparing to an occurence with different dates" do
23
+ expect(occ).to_not eq Occurrence.new(type: :daily, start_date: ZDate.new("20080825"))
24
+ end
25
+
26
+ it "is false when comparing to an occurrence with a different type" do
27
+ expect(occ).to_not eq Occurrence.new(type: :weekly, start_date: ZDate.new("20140128"))
28
+ end
29
+
30
+ it "is false when comparing to an occurence with a different interval" do
31
+ expect(occ).to_not eq Occurrence.new(type: :daily, start_date: ZDate.new("20140128"), interval: 3)
32
+ end
33
+
34
+ it "is true when comparing to an occurence with the same values" do
35
+ expect(occ).to eq Occurrence.new(type: :daily, start_date: ZDate.new("20140128"))
36
+ end
37
+ end
38
+ end
39
+ end
40
+
@@ -0,0 +1,94 @@
1
+ require "spec_helper"
2
+ require_relative "../../../lib/nickel/zdate"
3
+
4
+ module Nickel
5
+ describe ZDate do
6
+ describe "#get_next_date_from_date_of_month" do
7
+ let(:d1) { ZDate.new("20090927") }
8
+
9
+ it "is the next date with that day of the month" do
10
+ expect(d1.get_next_date_from_date_of_month(28)).to eq ZDate.new("20090928")
11
+ expect(d1.get_next_date_from_date_of_month(5)).to eq ZDate.new("20091005")
12
+ end
13
+
14
+ it "is nil when the current month has no such day of month" do
15
+ expect(d1.get_next_date_from_date_of_month(31)).to be nil
16
+ end
17
+ end
18
+
19
+ describe "#test_get_date_from_day_and_week_of_month" do
20
+ let(:d1) { ZDate.new('20090927') }
21
+
22
+ context "passed a negative number" do
23
+ it "is the nth-last occurance of that day of the week that month" do
24
+ expect(d1.get_date_from_day_and_week_of_month(ZDate::WED, -1)).to eq ZDate.new('20090930')
25
+ end
26
+ end
27
+
28
+ context "passed a positive number" do
29
+ it "is the nth occurance of that day of the week that month" do
30
+ expect(d1.get_date_from_day_and_week_of_month(ZDate::WED, 5)).to eq ZDate.new('20090930')
31
+ end
32
+
33
+ it "flows on into the next month if there are not enough days that month" do
34
+ expect(d1.get_date_from_day_and_week_of_month(ZDate::THU, 5)).to eq ZDate.new('20091001')
35
+ end
36
+ end
37
+ end
38
+
39
+ describe "#diff_in_days_to_this" do
40
+ let(:d1) { ZDate.new("20090927") }
41
+ let(:d2) { ZDate.new("20090930") }
42
+
43
+ context "passed a weekend date" do
44
+ it "is the number of days until that day of the week" do
45
+ expect(d1.diff_in_days_to_this(ZDate::SUN)).to eq 0
46
+ expect(d1.diff_in_days_to_this(ZDate::MON)).to eq 1
47
+ expect(d1.diff_in_days_to_this(ZDate::TUE)).to eq 2
48
+ expect(d1.diff_in_days_to_this(ZDate::WED)).to eq 3
49
+ expect(d1.diff_in_days_to_this(ZDate::THU)).to eq 4
50
+ expect(d1.diff_in_days_to_this(ZDate::FRI)).to eq 5
51
+ expect(d1.diff_in_days_to_this(ZDate::SAT)).to eq 6
52
+ end
53
+ end
54
+
55
+ context "passed a midweek date" do
56
+ it "is the number of days until that day of the week" do
57
+ expect(d2.diff_in_days_to_this(ZDate::WED)).to eq 0
58
+ expect(d2.diff_in_days_to_this(ZDate::THU)).to eq 1
59
+ expect(d2.diff_in_days_to_this(ZDate::FRI)).to eq 2
60
+ expect(d2.diff_in_days_to_this(ZDate::SAT)).to eq 3
61
+ expect(d2.diff_in_days_to_this(ZDate::SUN)).to eq 4
62
+ expect(d2.diff_in_days_to_this(ZDate::MON)).to eq 5
63
+ expect(d2.diff_in_days_to_this(ZDate::TUE)).to eq 6
64
+ end
65
+ end
66
+ end
67
+
68
+ describe "#to_date" do
69
+ it "converts to a Date" do
70
+ expect(ZDate.new('20090927').to_date).to eq Date.new(2009, 9, 27)
71
+ end
72
+ end
73
+
74
+ describe "#==" do
75
+ let(:d1) { ZDate.new('20090927') }
76
+
77
+ it "is true when the other ZDate is for the very same day" do
78
+ expect(d1).to eq ZDate.new('20090927')
79
+ end
80
+
81
+ it "is false when the other ZDate is for any other day" do
82
+ expect(d1).to_not eq ZDate.new('20100927')
83
+ end
84
+
85
+ it "is true when the other object a Date for the same day" do
86
+ expect(d1).to eq Date.new(2009, 9, 27)
87
+ end
88
+
89
+ it "is false when the other object is a Date for any other day" do
90
+ expect(d1).to_not eq Date.new(2010, 9, 27)
91
+ end
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,331 @@
1
+ require "spec_helper"
2
+ require_relative "../../../lib/nickel/ztime"
3
+
4
+ module Nickel
5
+ describe ZTime do
6
+ describe "#modify_such_that_is_before" do
7
+ specify "1200 to before 1200am is 1200" do
8
+ expect(ZTime.new("1200").modify_such_that_is_before(ZTime.new("1200", :am))).to eq ZTime.new("1200")
9
+ end
10
+
11
+ specify "1200 to before 1200pm is 1200am" do
12
+ expect(ZTime.new("1200").modify_such_that_is_before(ZTime.new("1200", :pm))).to eq ZTime.new("1200", :am)
13
+ end
14
+
15
+ specify "1 to before 2am is 1" do
16
+ expect(ZTime.new("1").modify_such_that_is_before(ZTime.new("2", :am))).to eq ZTime.new("1")
17
+ end
18
+
19
+ specify "10 to before 11pm is 10pm" do
20
+ expect(ZTime.new("10").modify_such_that_is_before(ZTime.new("11", :pm))).to eq ZTime.new("10", :pm)
21
+ end
22
+
23
+ specify "8 to before 11pm is 8" do
24
+ expect(ZTime.new("8").modify_such_that_is_before(ZTime.new("12", :pm))).to eq ZTime.new("8")
25
+ end
26
+
27
+ specify "0830 to before 0835am is 0830" do
28
+ expect(ZTime.new("0830").modify_such_that_is_before(ZTime.new("0835", :am))).to eq ZTime.new("0830")
29
+ end
30
+
31
+ specify "0830 to before 0835pm is 0830pm" do
32
+ expect(ZTime.new("0830").modify_such_that_is_before(ZTime.new("0835", :pm))).to eq ZTime.new("0830", :pm)
33
+ end
34
+
35
+ specify "0835 to before 0835pm is 0835" do
36
+ expect(ZTime.new("0835").modify_such_that_is_before(ZTime.new("0835", :pm))).to eq ZTime.new("0835")
37
+ end
38
+
39
+ specify "1021 to before 1223am is 1021pm" do
40
+ expect(ZTime.new("1021").modify_such_that_is_before(ZTime.new("1223", :am))).to eq ZTime.new("1021", :pm)
41
+ end
42
+
43
+ specify "12 to before 2am is 12am" do
44
+ expect(ZTime.new("12").modify_such_that_is_before(ZTime.new("2", :am))).to eq ZTime.new("12", :am)
45
+ end
46
+
47
+ specify "1220 to before 2am is 1220am" do
48
+ expect(ZTime.new("1220").modify_such_that_is_before(ZTime.new("2", :am))).to eq ZTime.new("1220", :am)
49
+ end
50
+
51
+ specify "1220 to before 12am is 1220" do
52
+ expect(ZTime.new("1220").modify_such_that_is_before(ZTime.new("12", :am))).to eq ZTime.new("1220")
53
+ end
54
+
55
+ specify "1220 to before 1220am is 1220" do
56
+ expect(ZTime.new("1220").modify_such_that_is_before(ZTime.new("1220", :am))).to eq ZTime.new("1220")
57
+ end
58
+
59
+ specify "0930 to before 5pm is 0930" do
60
+ expect(ZTime.new("0930").modify_such_that_is_before(ZTime.new("5", :pm))).to eq ZTime.new("0930")
61
+ end
62
+
63
+ specify "0930 to before 5am is 0930pm" do
64
+ expect(ZTime.new("0930").modify_such_that_is_before(ZTime.new("5", :am))).to eq ZTime.new("0930", :pm)
65
+ end
66
+
67
+ specify "1100 to before 0425pm is 1100" do
68
+ expect(ZTime.new("1100").modify_such_that_is_before(ZTime.new("0425", :pm))).to eq ZTime.new("1100")
69
+ end
70
+
71
+ specify "1100 to before 0425am is 1100pm" do
72
+ expect(ZTime.new("1100").modify_such_that_is_before(ZTime.new("0425", :am))).to eq ZTime.new("1100", :pm)
73
+ end
74
+
75
+ specify "0115 to before 0120am is 0115" do
76
+ expect(ZTime.new("0115").modify_such_that_is_before(ZTime.new("0120", :am))).to eq ZTime.new("0115")
77
+ end
78
+
79
+ specify "0115 to before 0120pm is 0115pm" do
80
+ expect(ZTime.new("0115").modify_such_that_is_before(ZTime.new("0120", :pm))).to eq ZTime.new("0115", :pm)
81
+ end
82
+
83
+ specify "1020 to before 1015am is 1020pm" do
84
+ expect(ZTime.new("1020").modify_such_that_is_before(ZTime.new("1015", :am))).to eq ZTime.new("1020", :pm)
85
+ end
86
+
87
+ specify "1020 to before 1015pm is 1020" do
88
+ expect(ZTime.new("1020").modify_such_that_is_before(ZTime.new("1015", :pm))).to eq ZTime.new("1020")
89
+ end
90
+
91
+ specify "1015 to before 1020am is 1015" do
92
+ expect(ZTime.new("1015").modify_such_that_is_before(ZTime.new("1020", :am))).to eq ZTime.new("1015")
93
+ end
94
+
95
+ specify "1015 to before 1020pm is 1015pm" do
96
+ expect(ZTime.new("1015").modify_such_that_is_before(ZTime.new("1020", :pm))).to eq ZTime.new("1015", :pm)
97
+ end
98
+ end
99
+
100
+ describe "#modify_such_that_is_after" do
101
+ specify "1200 to after 1200am is 1200am" do
102
+ expect(ZTime.new("1200").modify_such_that_is_after(ZTime.new("1200", :pm))).to eq ZTime.new("1200", :am)
103
+ end
104
+
105
+ specify "1200 to after 1200am is 1200" do
106
+ expect(ZTime.new("1200").modify_such_that_is_after(ZTime.new("1200", :am))).to eq ZTime.new("1200")
107
+ end
108
+
109
+ specify "2 to after 1am is 2" do
110
+ expect(ZTime.new("2").modify_such_that_is_after(ZTime.new("1", :am))).to eq ZTime.new("2")
111
+ end
112
+
113
+ specify "11 to after 10pm is 11pm" do
114
+ expect(ZTime.new("11").modify_such_that_is_after(ZTime.new("10", :pm))).to eq ZTime.new("11", :pm)
115
+ end
116
+
117
+ specify "12 to after 8am is 12" do
118
+ expect(ZTime.new("12").modify_such_that_is_after(ZTime.new("8", :am))).to eq ZTime.new("12")
119
+ end
120
+
121
+ specify "0835 to after 0830am is 0835" do
122
+ expect(ZTime.new("0835").modify_such_that_is_after(ZTime.new("0830", :am))).to eq ZTime.new("0835")
123
+ end
124
+
125
+ specify "0835 to after 0830pm is 0835pm" do
126
+ expect(ZTime.new("0835").modify_such_that_is_after(ZTime.new("0830", :pm))).to eq ZTime.new("0835", :pm)
127
+ end
128
+
129
+ specify "0835 to after 0835am is 0835pm" do
130
+ expect(ZTime.new("0835").modify_such_that_is_after(ZTime.new("0835", :am))).to eq ZTime.new("0835", :pm)
131
+ end
132
+
133
+ specify "0835 to after 0835pm is 0835" do
134
+ expect(ZTime.new("0835").modify_such_that_is_after(ZTime.new("0835", :pm))).to eq ZTime.new("0835")
135
+ end
136
+
137
+ specify "1223 to after 1021pm is 1223am" do
138
+ expect(ZTime.new("1223").modify_such_that_is_after(ZTime.new("1021", :pm))).to eq ZTime.new("1223", :am)
139
+ end
140
+
141
+ specify "2 to after 12am is 2" do
142
+ expect(ZTime.new("2").modify_such_that_is_after(ZTime.new("12", :am))).to eq ZTime.new("2")
143
+ end
144
+
145
+ specify "2 to after 1220am is 2" do
146
+ expect(ZTime.new("2").modify_such_that_is_after(ZTime.new("1220", :am))).to eq ZTime.new("2")
147
+ end
148
+
149
+ specify "12 to after 1220am is 12" do
150
+ expect(ZTime.new("12").modify_such_that_is_after(ZTime.new("1220", :am))).to eq ZTime.new("12")
151
+ end
152
+
153
+ specify "1220 to after 1220pm is 1220am" do
154
+ expect(ZTime.new("1220").modify_such_that_is_after(ZTime.new("1220", :pm))).to eq ZTime.new("1220", :am)
155
+ end
156
+
157
+ specify "5 to after 0930am is 5pm" do
158
+ expect(ZTime.new("5").modify_such_that_is_after(ZTime.new("0930", :am))).to eq ZTime.new("5", :pm)
159
+ end
160
+
161
+ specify "5 to after 0930pm is 5" do
162
+ expect(ZTime.new("5").modify_such_that_is_after(ZTime.new("0930", :pm))).to eq ZTime.new("5")
163
+ end
164
+
165
+ specify "0425 to after 1100am is 0425pm" do
166
+ expect(ZTime.new("0425").modify_such_that_is_after(ZTime.new("1100", :am))).to eq ZTime.new("0425", :pm)
167
+ end
168
+
169
+ specify "0425 to after 1100pm is 0425" do
170
+ expect(ZTime.new("0425").modify_such_that_is_after(ZTime.new("1100", :pm))).to eq ZTime.new("0425")
171
+ end
172
+
173
+ specify "0120 to after 0115am is 0120" do
174
+ expect(ZTime.new("0120").modify_such_that_is_after(ZTime.new("0115", :am))).to eq ZTime.new("0120")
175
+ end
176
+
177
+ specify "0120 to after 0115pm is 0120pm" do
178
+ expect(ZTime.new("0120").modify_such_that_is_after(ZTime.new("0115", :pm))).to eq ZTime.new("0120", :pm)
179
+ end
180
+
181
+ specify "1015 to after 1020pm is 1015" do
182
+ expect(ZTime.new("1015").modify_such_that_is_after(ZTime.new("1020", :pm))).to eq ZTime.new("1015")
183
+ end
184
+
185
+ specify "1015 to after 1020am is 1015pm" do
186
+ expect(ZTime.new("1015").modify_such_that_is_after(ZTime.new("1020", :am))).to eq ZTime.new("1015", :pm)
187
+ end
188
+
189
+ specify "1020 to after 1015pm is 1020pm" do
190
+ expect(ZTime.new("1020").modify_such_that_is_after(ZTime.new("1015", :pm))).to eq ZTime.new("1020", :pm)
191
+ end
192
+
193
+ specify "1020 to after 1015am is 1020" do
194
+ expect(ZTime.new("1020").modify_such_that_is_after(ZTime.new("1015", :am))).to eq ZTime.new("1020")
195
+ end
196
+ end
197
+
198
+ describe "#am_pm_modifier" do
199
+
200
+ context "passed one ztime" do
201
+ it "sets am/pm if not set" do
202
+ t = ZTime.new("7", :pm)
203
+ ZTime.am_pm_modifier(t)
204
+ expect(t).to eq ZTime.new("7", :pm)
205
+ end
206
+ end
207
+
208
+ context "passed two ztimes" do
209
+ it "sets am/pm if not set" do
210
+ tz = [ZTime.new("7", :pm), ZTime.new("8")]
211
+ ZTime.am_pm_modifier(*tz)
212
+ expect(tz).to eq [ZTime.new("7", :pm), ZTime.new("8", :pm)]
213
+ end
214
+ end
215
+
216
+ context "passed three ztimes" do
217
+ it "sets am/pm if not set" do
218
+ tz = [ZTime.new("7", :pm), ZTime.new("8", :pm), ZTime.new("9")]
219
+ ZTime.am_pm_modifier(*tz)
220
+ expect(tz).to eq [ZTime.new("7", :pm), ZTime.new("8", :pm), ZTime.new("9", :pm)]
221
+ end
222
+ end
223
+
224
+ context "passed five ztimes" do
225
+ it "sets am/pm if not set" do
226
+ tz = [ZTime.new("7"), ZTime.new("8", :am), ZTime.new("9"), ZTime.new("4", :pm), ZTime.new("7")]
227
+ ZTime.am_pm_modifier(*tz)
228
+ expect(tz).to eq [ZTime.new("7", :am), ZTime.new("8", :am), ZTime.new("9", :am), ZTime.new("4", :pm), ZTime.new("7", :pm)]
229
+ end
230
+ end
231
+ end
232
+
233
+ describe "#to_time" do
234
+ it "converts to a Time on todays date" do
235
+ expect(ZTime.new("161718").to_time).to eq Time.parse("16:17:18")
236
+ end
237
+ end
238
+
239
+ describe "#==" do
240
+ let(:t1) { ZTime.new("161718") }
241
+
242
+ it "is true when the other ZTime is for the very same time of day" do
243
+ expect(t1).to eq ZTime.new('161718')
244
+ end
245
+
246
+ it "is false when the other ZTime is for any other time" do
247
+ expect(t1).to_not eq ZTime.new('171819')
248
+ end
249
+
250
+ it "is true when the other object is a Time for the same time of day" do
251
+ expect(t1).to eq Time.parse("16:17:18")
252
+ end
253
+
254
+ it "is false when the other object is a Time for any other time" do
255
+ expect(t1).to_not eq Time.parse("17:18:19")
256
+ end
257
+ end
258
+
259
+ describe "#hour_str" do
260
+ it "is the hour in the day as a string" do
261
+ expect(ZTime.new("161718").hour_str).to eql("16")
262
+ end
263
+ end
264
+
265
+ describe "#min_str" do
266
+ it "is the minutes past the hour as a string" do
267
+ expect(ZTime.new("161718").min_str).to eql("17")
268
+ end
269
+ end
270
+
271
+ describe "#sec_str" do
272
+ it "is the seconds into the minute as a string" do
273
+ expect(ZTime.new("161718").sec_str).to eql("18")
274
+ end
275
+ end
276
+
277
+ describe "#minute_str", :deprecated do
278
+ let(:t1) { ZTime.new("161718") }
279
+
280
+ it "delegates to #min_str" do
281
+ expect(t1).to receive(:min_str)
282
+ t1.minute_str
283
+ end
284
+ end
285
+
286
+ describe "#second_str", :deprecated do
287
+ let(:t1) { ZTime.new("161718") }
288
+
289
+ it "delegates to #sec_str" do
290
+ expect(t1).to receive(:sec_str)
291
+ t1.second_str
292
+ end
293
+ end
294
+
295
+ describe "#hour" do
296
+ it "is the hour in the day" do
297
+ expect(ZTime.new("161718").hour).to eql(16)
298
+ end
299
+ end
300
+
301
+ describe "#min" do
302
+ it "is the minutes past the hour" do
303
+ expect(ZTime.new("161718").min).to eql(17)
304
+ end
305
+ end
306
+
307
+ describe "#sec" do
308
+ it "is the seconds into the minute" do
309
+ expect(ZTime.new("161718").sec).to eql(18)
310
+ end
311
+ end
312
+
313
+ describe "#minute", :deprecated do
314
+ let(:t1) { ZTime.new("161718") }
315
+
316
+ it "delegates to #min" do
317
+ expect(t1).to receive(:min)
318
+ t1.minute
319
+ end
320
+ end
321
+
322
+ describe "#second", :deprecated do
323
+ let(:t1) { ZTime.new("161718") }
324
+
325
+ it "delegates to #sec" do
326
+ expect(t1).to receive(:sec)
327
+ t1.second
328
+ end
329
+ end
330
+ end
331
+ end