cronex 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,22 @@
1
+ require 'cronex'
2
+
3
+ module Cronex
4
+ describe ExpressionDescriptor do
5
+
6
+ subject(:expression) { '* * * * *' }
7
+
8
+ context 'casing:' do
9
+ it 'sentence' do
10
+ expect(desc(expression, casing: :sentence)).to eq('Every minute')
11
+ end
12
+
13
+ it 'title' do
14
+ expect(desc(expression, casing: :title)).to eq('Every Minute')
15
+ end
16
+
17
+ it 'lower' do
18
+ expect(desc(expression, casing: :lower)).to eq('every minute')
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,363 @@
1
+ require 'cronex'
2
+
3
+ module Cronex
4
+ describe ExpressionDescriptor do
5
+
6
+ let(:opts) { { zero_based_dow: false } }
7
+
8
+ it 'every second' do
9
+ expect(desc('* * * * * *')).to eq('Every second')
10
+ end
11
+
12
+ it 'every 45 seconds' do
13
+ expect(desc('*/45 * * * * *')).to eq('Every 45 seconds')
14
+ end
15
+
16
+ it 'minute span' do
17
+ expect(desc('0-10 11 * * *')).to eq('Every minute between 11:00 AM and 11:10 AM')
18
+ end
19
+
20
+ context 'every minute' do
21
+ it 'every minute' do
22
+ expect(desc('* * * * *')).to eq('Every minute')
23
+ end
24
+
25
+ it 'every minute */1' do
26
+ expect(desc('*/1 * * * *')).to eq('Every minute')
27
+ end
28
+
29
+ it 'every minute 0 0/1' do
30
+ expect(desc('0 0/1 * * * ?')).to eq('Every minute')
31
+ end
32
+ end
33
+
34
+ context 'every X minutes:' do
35
+ it 'every 5 minutes' do
36
+ expect(desc('*/5 * * * *')).to eq('Every 5 minutes')
37
+ end
38
+
39
+ it 'every 5 minute 0 */5' do
40
+ expect(desc('0 */5 * * * *')).to eq('Every 5 minutes')
41
+ end
42
+
43
+ it 'every 10 minutes 0 0/10' do
44
+ expect(desc('0 0/10 * * * ?')).to eq('Every 10 minutes')
45
+ end
46
+ end
47
+
48
+ context 'every hour:' do
49
+ it 'every hour 0 0' do
50
+ expect(desc('0 0 * * * ?')).to eq('Every hour')
51
+ end
52
+
53
+ it 'every hour 0 0 0/1' do
54
+ expect(desc('0 0 0/1 * * ?')).to eq('Every hour')
55
+ end
56
+ end
57
+
58
+ it 'daily at time' do
59
+ expect(desc('30 11 * * *')).to eq('At 11:30 AM')
60
+ end
61
+
62
+ context 'time of day certain days of week:' do
63
+ it 'time of day on MON-FRI' do
64
+ expect(desc('0 23 ? * MON-FRI')).to eq('At 11:00 PM, Monday through Friday')
65
+ end
66
+
67
+ it 'time of day on 1-5' do
68
+ expect(desc('30 11 * * 1-5')).to eq('At 11:30 AM, Monday through Friday')
69
+ end
70
+ end
71
+
72
+ it 'one month only' do
73
+ expect(desc('* * * 3 *')).to eq('Every minute, only in March')
74
+ end
75
+
76
+ it 'two months only' do
77
+ expect(desc('* * * 3,6 *')).to eq('Every minute, only in March and June')
78
+ end
79
+
80
+ it 'two times each afternoon' do
81
+ expect(desc('30 14,16 * * *')).to eq('At 2:30 PM and 4:30 PM')
82
+ end
83
+
84
+ it 'three times daily' do
85
+ expect(desc('30 6,14,16 * * *')).to eq('At 6:30 AM, 2:30 PM and 4:30 PM')
86
+ end
87
+
88
+ context 'once a week:' do
89
+ it 'once a week 0' do
90
+ expect(desc('46 9 * * 0')).to eq('At 9:46 AM, only on Sunday')
91
+ end
92
+
93
+ it 'once a week SUN' do
94
+ expect(desc('46 9 * * SUN')).to eq('At 9:46 AM, only on Sunday')
95
+ end
96
+
97
+ it 'once a week 7' do
98
+ expect(desc('46 9 * * 7')).to eq('At 9:46 AM, only on Sunday')
99
+ end
100
+
101
+ it 'once a week 1' do
102
+ expect(desc('46 9 * * 1')).to eq('At 9:46 AM, only on Monday')
103
+ end
104
+
105
+ it 'once a week 6' do
106
+ expect(desc('46 9 * * 6')).to eq('At 9:46 AM, only on Saturday')
107
+ end
108
+ end
109
+
110
+ context 'once a week non zero based:' do
111
+ it 'once a week 1' do
112
+ expect(desc('46 9 * * 1', opts)).to eq('At 9:46 AM, only on Sunday')
113
+ end
114
+
115
+ it 'once a week SUN' do
116
+ expect(desc('46 9 * * SUN', opts)).to eq('At 9:46 AM, only on Sunday')
117
+ end
118
+
119
+ it 'once a week 2' do
120
+ expect(desc('46 9 * * 2', opts)).to eq('At 9:46 AM, only on Monday')
121
+ end
122
+
123
+ it 'once a week 7' do
124
+ expect(desc('46 9 * * 7', opts)).to eq('At 9:46 AM, only on Saturday')
125
+ end
126
+ end
127
+
128
+ context 'twice a week:' do
129
+ it 'twice a week 1,2' do
130
+ expect(desc('46 9 * * 1,2')).to eq('At 9:46 AM, only on Monday and Tuesday')
131
+ end
132
+
133
+ it 'twice a week MON,TUE' do
134
+ expect(desc('46 9 * * MON,TUE')).to eq('At 9:46 AM, only on Monday and Tuesday')
135
+ end
136
+
137
+ it 'twice a week 0,6' do
138
+ expect(desc('46 9 * * 0,6')).to eq('At 9:46 AM, only on Sunday and Saturday')
139
+ end
140
+
141
+ it 'twice a week 6,7' do
142
+ expect(desc('46 9 * * 6,7')).to eq('At 9:46 AM, only on Saturday and Sunday')
143
+ end
144
+ end
145
+
146
+ context 'twice a week non zero based:' do
147
+ it 'twice a week 1,2' do
148
+ expect(desc('46 9 * * 1,2', opts)).to eq('At 9:46 AM, only on Sunday and Monday')
149
+ end
150
+
151
+ it 'twice a week SUN,MON' do
152
+ expect(desc('46 9 * * SUN,MON', opts)).to eq('At 9:46 AM, only on Sunday and Monday')
153
+ end
154
+
155
+ it 'twice a week 6,7' do
156
+ expect(desc('46 9 * * 6,7', opts)).to eq('At 9:46 AM, only on Friday and Saturday')
157
+ end
158
+ end
159
+
160
+ it 'day of month' do
161
+ expect(desc('23 12 15 * *')).to eq('At 12:23 PM, on day 15 of the month')
162
+ end
163
+
164
+ it 'day of month ignores day of week' do
165
+ expect(desc('23 12 15 * SUN')).to eq('At 12:23 PM, on day 15 of the month')
166
+ end
167
+
168
+ it 'month name' do
169
+ expect(desc('23 12 * JAN *')).to eq('At 12:23 PM, only in January')
170
+ end
171
+
172
+ it 'day of month with question mark' do
173
+ expect(desc('23 12 ? JAN *')).to eq('At 12:23 PM, only in January')
174
+ end
175
+
176
+ it 'month name range 2' do
177
+ expect(desc('23 12 * JAN-FEB *')).to eq('At 12:23 PM, January through February')
178
+ end
179
+
180
+ it 'month name range 3' do
181
+ expect(desc('23 12 * JAN-MAR *')).to eq('At 12:23 PM, January through March')
182
+ end
183
+
184
+ it 'day of week name' do
185
+ expect(desc('23 12 * * SUN')).to eq('At 12:23 PM, only on Sunday')
186
+ end
187
+
188
+ context 'day of week range:' do
189
+ it 'day of week range MON-FRI' do
190
+ expect(desc('*/5 15 * * MON-FRI')).to eq('Every 5 minutes, at 3:00 PM, Monday through Friday')
191
+ end
192
+
193
+ it 'day of week range 0-6' do
194
+ expect(desc('*/5 15 * * 0-6')).to eq('Every 5 minutes, at 3:00 PM, Sunday through Saturday')
195
+ end
196
+
197
+ it 'day of week range 6-7' do
198
+ expect(desc('*/5 15 * * 6-7')).to eq('Every 5 minutes, at 3:00 PM, Saturday through Sunday')
199
+ end
200
+ end
201
+
202
+ context 'day of week once in month:' do
203
+ it 'day of week once MON#3' do
204
+ expect(desc('* * * * MON#3')).to eq('Every minute, on the third Monday of the month')
205
+ end
206
+
207
+ it 'day of week once 0#3' do
208
+ expect(desc('* * * * 0#3')).to eq('Every minute, on the third Sunday of the month')
209
+ end
210
+ end
211
+
212
+ context 'last day of week of the month:' do
213
+ it 'last day of week 4L' do
214
+ expect(desc('* * * * 4L')).to eq('Every minute, on the last Thursday of the month')
215
+ end
216
+
217
+ it 'last day of week 0L' do
218
+ expect(desc('* * * * 0L')).to eq('Every minute, on the last Sunday of the month')
219
+ end
220
+ end
221
+
222
+ it 'last day of the month' do
223
+ expect(desc('*/5 * L JAN *')).to eq('Every 5 minutes, on the last day of the month, only in January')
224
+ end
225
+
226
+ it 'time of day with seconds' do
227
+ expect(desc('30 02 14 * * *')).to eq('At 2:02:30 PM')
228
+ end
229
+
230
+ it 'second intervals' do
231
+ expect(desc('5-10 * * * * *')).to eq('Seconds 5 through 10 past the minute')
232
+ end
233
+
234
+ it 'second minutes hours intervals' do
235
+ expect(desc('5-10 30-35 10-12 * * *')).to eq(
236
+ 'Seconds 5 through 10 past the minute, minutes 30 through 35 past the hour, between 10:00 AM and 12:59 PM')
237
+ end
238
+
239
+ it 'every 5 minutes at 30 seconds' do
240
+ expect(desc('30 */5 * * * *')).to eq('At 30 seconds past the minute, every 5 minutes')
241
+ end
242
+
243
+ it 'minutes past the hour range' do
244
+ expect(desc('0 30 10-13 ? * WED,FRI')).to eq(
245
+ 'At 30 minutes past the hour, between 10:00 AM and 1:59 PM, only on Wednesday and Friday')
246
+ end
247
+
248
+ it 'seconds past the minute interval' do
249
+ expect(desc('10 0/5 * * * ?')).to eq('At 10 seconds past the minute, every 5 minutes')
250
+ end
251
+
252
+ it 'between with interval' do
253
+ expect(desc('2-59/3 1,9,22 11-26 1-6 ?')).to eq(
254
+ 'Every 3 minutes, minutes 02 through 59 past the hour, at 1:00 AM, 9:00 AM and 10:00 PM, between day 11 and 26 of the month, January through June')
255
+ end
256
+
257
+ it 'recurring first of month' do
258
+ expect(desc('0 0 6 1/1 * ?')).to eq('At 6:00 AM')
259
+ end
260
+
261
+ it 'minutes past the hour' do
262
+ expect(desc('0 5 0/1 * * ?')).to eq('At 05 minutes past the hour')
263
+ end
264
+
265
+ it 'every past the hour' do
266
+ expect(desc('0 0,5,10,15,20,25,30,35,40,45,50,55 * ? * *')).to eq(
267
+ 'At 00, 05, 10, 15, 20, 25, 30, 35, 40, 45, 50 and 55 minutes past the hour')
268
+ end
269
+
270
+ it 'every x minute past the hour with interval' do
271
+ expect(desc('0 0-30/2 17 ? * MON-FRI')).to eq(
272
+ 'Every 2 minutes, minutes 00 through 30 past the hour, at 5:00 PM, Monday through Friday')
273
+ end
274
+
275
+ it 'one year only with seconds' do
276
+ expect(desc('* * * * * * 2013')).to eq('Every second, only in 2013')
277
+ end
278
+
279
+ it 'one year only without seconds' do
280
+ expect(desc('* * * * * 2013')).to eq('Every minute, only in 2013')
281
+ end
282
+
283
+ it 'two years only' do
284
+ expect(desc('* * * * * 2013,2014')).to eq('Every minute, only in 2013 and 2014')
285
+ end
286
+
287
+ it 'year range 2' do
288
+ expect(desc('23 12 * JAN-FEB * 2013-2014')).to eq('At 12:23 PM, January through February, 2013 through 2014')
289
+ end
290
+
291
+ it 'year range 3' do
292
+ expect(desc('23 12 * JAN-MAR * 2013-2015')).to eq('At 12:23 PM, January through March, 2013 through 2015')
293
+ end
294
+
295
+ context 'multi part range seconds:' do
296
+ it 'multi part range seconds 2,4-5' do
297
+ expect(desc('2,4-5 1 * * *')).to eq('Minutes 02,04 through 05 past the hour, at 1:00 AM')
298
+ end
299
+
300
+ it 'multi part range seconds 2,26-28' do
301
+ expect(desc('2,26-28 18 * * *')).to eq('Minutes 02,26 through 28 past the hour, at 6:00 PM')
302
+ end
303
+ end
304
+
305
+ context 'minutes past the hour:' do
306
+ it 'minutes past the hour 5,10' do
307
+ expect(desc('5,10 0 * * *')).to eq('At 05 and 10 minutes past the hour')
308
+ end
309
+
310
+ it 'minutes past the hour 5,10 day 2' do
311
+ expect(desc('5,10 0 2 * *')).to eq('At 05 and 10 minutes past the hour, on day 2 of the month')
312
+ end
313
+
314
+ it 'minutes past the hour 5/10 day 2' do
315
+ expect(desc('5/10 0 2 * *')).to eq('Every 10 minutes, starting at 05 minutes past the hour, on day 2 of the month')
316
+ end
317
+ end
318
+
319
+ context 'seconds past the minute:' do
320
+ it 'seconds past the minute 5,6' do
321
+ expect(desc('5,6 0 0 * * *')).to eq('At 5 and 6 seconds past the minute')
322
+ end
323
+
324
+ it 'seconds past the minute 5,6 at 1' do
325
+ expect(desc('5,6 0 1 * * *')).to eq('At 5 and 6 seconds past the minute, at 1:00 AM')
326
+ end
327
+
328
+ it 'seconds past the minute 5,6 day 2' do
329
+ expect(desc('5,6 0 0 2 * *')).to eq('At 5 and 6 seconds past the minute, on day 2 of the month')
330
+ end
331
+ end
332
+
333
+ context 'increments starting at X > 1:' do
334
+ it 'second increments' do
335
+ expect(desc('5/15 0 * * * *')).to eq('Every 15 seconds, starting at 5 seconds past the minute')
336
+ end
337
+
338
+ it 'minute increments' do
339
+ expect(desc('30/10 * * * *')).to eq('Every 10 minutes, starting at 30 minutes past the hour')
340
+ end
341
+
342
+ it 'hour increments' do
343
+ expect(desc('0 30 2/6 * * ?')).to eq('At 30 minutes past the hour, every 6 hours, starting at 2:00 AM')
344
+ end
345
+
346
+ it 'day of month increments' do
347
+ expect(desc('0 30 8 2/7 * *')).to eq('At 8:30 AM, every 7 days, starting on day 2 of the month')
348
+ end
349
+
350
+ it 'day of week increments' do
351
+ expect(desc('0 30 11 * * 2/2')).to eq('At 11:30 AM, every 2 days of the week, starting on Tuesday')
352
+ end
353
+
354
+ it 'month increments' do
355
+ expect(desc('0 20 10 * 2/3 THU')).to eq('At 10:20 AM, only on Thursday, every 3 months, starting in February')
356
+ end
357
+
358
+ it 'year increments' do
359
+ expect(desc('0 0 0 1 MAR * 2010/5')).to eq('At 0:00 AM, on day 1 of the month, only in March, every 5 years, starting in 2010')
360
+ end
361
+ end
362
+ end
363
+ end
@@ -0,0 +1,11 @@
1
+ require 'rspec'
2
+
3
+ RSpec.configure do |config|
4
+ config.expect_with :rspec do |c|
5
+ c.syntax = :expect
6
+ end
7
+
8
+ def desc(expression, opts = {})
9
+ Cronex::ExpressionDescriptor.new(expression, opts).description
10
+ end
11
+ end
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cronex
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Adrian Kazaku
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-10-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: pry
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '0.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '0.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '10.1'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '10.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '3.1'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '3.1'
55
+ description: Ruby library that converts cron expressions into human readable strings
56
+ email:
57
+ - alpinweis@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .gitignore
63
+ - .rspec
64
+ - .rubocop.yml
65
+ - CHANGELOG.md
66
+ - Gemfile
67
+ - LICENSE.md
68
+ - README.md
69
+ - Rakefile
70
+ - cronex.gemspec
71
+ - lib/cronex.rb
72
+ - lib/cronex/description.rb
73
+ - lib/cronex/description/base.rb
74
+ - lib/cronex/description/day_of_month.rb
75
+ - lib/cronex/description/day_of_week.rb
76
+ - lib/cronex/description/hours.rb
77
+ - lib/cronex/description/minutes.rb
78
+ - lib/cronex/description/month.rb
79
+ - lib/cronex/description/seconds.rb
80
+ - lib/cronex/description/year.rb
81
+ - lib/cronex/errors.rb
82
+ - lib/cronex/exp_descriptor.rb
83
+ - lib/cronex/parser.rb
84
+ - lib/cronex/resource.rb
85
+ - lib/cronex/utils.rb
86
+ - lib/cronex/version.rb
87
+ - resources/resources_en.yml
88
+ - spec/casing_spec.rb
89
+ - spec/exp_descriptor_spec.rb
90
+ - spec/spec_helper.rb
91
+ homepage: https://github.com/alpinweis/cronex
92
+ licenses:
93
+ - Apache 2
94
+ metadata: {}
95
+ post_install_message:
96
+ rdoc_options: []
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ! '>='
102
+ - !ruby/object:Gem::Version
103
+ version: 1.9.3
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ! '>='
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ requirements: []
110
+ rubyforge_project:
111
+ rubygems_version: 2.4.8
112
+ signing_key:
113
+ specification_version: 4
114
+ summary: Ruby library that converts cron expressions into human readable strings
115
+ test_files:
116
+ - spec/casing_spec.rb
117
+ - spec/exp_descriptor_spec.rb
118
+ - spec/spec_helper.rb