ice_cube_cron 0.0.1 → 0.0.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 35437710e09561f1e31c5f37b0e612a21866395e
4
- data.tar.gz: e4648fbf6cd9fee9e5ad7f2f260d2bbc4eeb4412
3
+ metadata.gz: f7aa5090dd5b494487fe66f7f731bed0b90b59ce
4
+ data.tar.gz: 7822df6b8b1d227cb23ad9e64f7db313084476b6
5
5
  SHA512:
6
- metadata.gz: 6edd59aebe07b5926ffe46ee99faa64ac4491b202c837ae09dbad0ade219eb4df2de35a1ad7946363755c953e8d56d6fa4462c9ac436e29cde7bf64c98b76696
7
- data.tar.gz: 16c1988525cf23b6fb90f40b0a188dde5ce72fd45fdcd3582c75dd05f2aafc1112149c1670231520f7a34ad5fdf04b4917d7e9ee894343bfba8c63cc2da18220
6
+ metadata.gz: 92b1a9335aaa0dbc98bcb5ef7966d17da696567158c7afd6e1308b19d2118564928cd233e89e19017a4da8bba3003c1761057156a0f8d9d43d2e1a9031a08281
7
+ data.tar.gz: f884daabb064dc2ab03802bef9cf9361cd05ac1b2e85d91e190b1d35d28fb67b19ac29940cb9f2e5561b44c0da6ce386ce9ebc5569ce45314a2657e89ce6c7c1
data/README.md CHANGED
@@ -35,14 +35,16 @@ Cron expression can be specified using a hash or a string in the format:
35
35
 
36
36
 
37
37
  ```ruby
38
+ require 'ice_cube_cron'
39
+
38
40
  # using cron expression string (not supported yet)
39
41
  schedule = ::IceCube::Schedule.from_cron(::Date.current, "* * * * 5")
40
42
 
41
43
  # using hash
42
- schedule = ::IceCube::Schedule.from_cron(::Date.current, :repeat_day => 5)
44
+ schedule = ::IceCube::Schedule.from_cron(::Date.new(2015, 1, 5), :repeat_day => 5)
43
45
 
44
46
  schedule.occurrences_between(::Date.new(2015, 3, 5), ::Date.new(2015, 6, 5))
45
- # => [2015-03-05, 2015-04-05, 2015-06-05]
47
+ # => [2015-03-05 00:00:00 UTC, 2015-04-05 00:00:00 UTC, 2015-05-05 00:00:00 UTC, 2015-06-05 00:00:00 UTC]
46
48
  ```
47
49
 
48
50
  ## recurrence rule examples (date)
data/lib/ice_cube_cron.rb CHANGED
@@ -7,4 +7,5 @@ require 'ice_cube_cron/version'
7
7
  require 'ice_cube_cron/util'
8
8
  require 'ice_cube_cron/rule_builder'
9
9
  require 'ice_cube_cron/expression_parser'
10
+ require 'ice_cube_cron/extension'
10
11
  require 'ice_cube_cron/base'
@@ -1,13 +1,5 @@
1
1
  module IceCube
2
- class << self
3
- def from_cron(start_time, expression = {})
4
- expression_parser = ::IceCubeCron::ExpressionParser.new(expression)
5
- rule = ::IceCubeCron::RuleBuilder.new.build_rule(expression_parser)
6
-
7
- schedule = ::IceCube::Schedule.new(::IceCubeCron::Util.sanitize_date_param(start_time))
8
- schedule.add_recurrence_rule(rule)
9
-
10
- schedule
11
- end
2
+ class Schedule
3
+ extend ::IceCubeCron::Extension
12
4
  end
13
5
  end
@@ -0,0 +1,13 @@
1
+ module IceCubeCron
2
+ module Extension
3
+ def from_cron(start_time, expression = {})
4
+ expression_parser = ::IceCubeCron::ExpressionParser.new(expression)
5
+ rule = ::IceCubeCron::RuleBuilder.new.build_rule(expression_parser)
6
+
7
+ schedule = ::IceCube::Schedule.new(::IceCubeCron::Util.sanitize_date_param(start_time))
8
+ schedule.add_recurrence_rule(rule)
9
+
10
+ schedule
11
+ end
12
+ end
13
+ end
@@ -1,3 +1,3 @@
1
1
  module IceCubeCron
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  end
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  describe ::IceCubeCron do
4
4
  context 'repeat options' do
5
5
  describe 'monthly' do
6
- let(:ice_cube_model) { ::IceCube.from_cron(::Date.new(2015, 7, 1), :repeat_day => '1') }
6
+ let(:ice_cube_model) { ::IceCube::Schedule.from_cron(::Date.new(2015, 7, 1), :repeat_day => '1') }
7
7
 
8
8
  it 'for same day' do
9
9
  expect(ice_cube_model.occurrences_between(::Date.new(2015, 7, 1), ::Date.new(2015, 7, 1))).to eq([::Date.new(2015, 7, 1)])
@@ -15,7 +15,7 @@ describe ::IceCubeCron do
15
15
  end
16
16
 
17
17
  describe 'twice monthly' do
18
- let(:ice_cube_model) { ::IceCube.from_cron(::Date.new(2015, 7, 1), :repeat_day => '1,15') }
18
+ let(:ice_cube_model) { ::IceCube::Schedule.from_cron(::Date.new(2015, 7, 1), :repeat_day => '1,15') }
19
19
 
20
20
  it 'for one month' do
21
21
  expect(ice_cube_model.occurrences_between(::Date.new(2015, 7, 1), ::Date.new(2015, 7, 31))).to eq([::Date.new(2015, 7, 1), ::Date.new(2015, 7, 15)])
@@ -28,7 +28,7 @@ describe ::IceCubeCron do
28
28
 
29
29
  describe 'bi-monthly' do
30
30
  let(:ice_cube_model) do
31
- ::IceCube.from_cron(
31
+ ::IceCube::Schedule.from_cron(
32
32
  ::Date.new(2015, 5, 1),
33
33
  :repeat_day => '1',
34
34
  :repeat_interval => '2'
@@ -46,7 +46,7 @@ describe ::IceCubeCron do
46
46
 
47
47
  describe 'every week' do
48
48
  let(:ice_cube_model) do
49
- ::IceCube.from_cron(
49
+ ::IceCube::Schedule.from_cron(
50
50
  ::Date.new(2015, 7, 6),
51
51
  :repeat_weekday => '1'
52
52
  )
@@ -85,7 +85,7 @@ describe ::IceCubeCron do
85
85
 
86
86
  describe 'bi-weekly' do
87
87
  let(:ice_cube_model) do
88
- ::IceCube.from_cron(
88
+ ::IceCube::Schedule.from_cron(
89
89
  ::Date.new(2015, 7, 6),
90
90
  :repeat_weekday => '1',
91
91
  :repeat_interval => '2'
@@ -125,7 +125,7 @@ describe ::IceCubeCron do
125
125
 
126
126
  describe 'annually' do
127
127
  let(:ice_cube_model) do
128
- ::IceCube.from_cron(
128
+ ::IceCube::Schedule.from_cron(
129
129
  ::Date.new(2015, 1, 1),
130
130
  :repeat_month => 2
131
131
  )
@@ -142,7 +142,7 @@ describe ::IceCubeCron do
142
142
 
143
143
  describe 'bi-annually' do
144
144
  let(:ice_cube_model) do
145
- ::IceCube.from_cron(
145
+ ::IceCube::Schedule.from_cron(
146
146
  ::Date.new(2015, 1, 1),
147
147
  :repeat_interval => 2,
148
148
  :repeat_month => 2,
@@ -158,7 +158,7 @@ describe ::IceCubeCron do
158
158
  describe 'last weekday of month' do
159
159
  context '31 day month' do
160
160
  let(:ice_cube_model) do
161
- ::IceCube.from_cron(
161
+ ::IceCube::Schedule.from_cron(
162
162
  ::Date.new(2015, 1, 1),
163
163
  :repeat_weekday => '5L'
164
164
  )
@@ -171,7 +171,7 @@ describe ::IceCubeCron do
171
171
 
172
172
  context '29 day month' do
173
173
  let(:ice_cube_model) do
174
- ::IceCube.from_cron(
174
+ ::IceCube::Schedule.from_cron(
175
175
  ::Date.new(2015, 1, 1),
176
176
  :repeat_weekday => '3L'
177
177
  )
@@ -186,7 +186,7 @@ describe ::IceCubeCron do
186
186
  describe 'last day of month' do
187
187
  context '31 day month' do
188
188
  let(:ice_cube_model) do
189
- ::IceCube.from_cron(
189
+ ::IceCube::Schedule.from_cron(
190
190
  ::Date.new(2015, 1, 1),
191
191
  :repeat_day => 'L'
192
192
  )
@@ -200,7 +200,7 @@ describe ::IceCubeCron do
200
200
 
201
201
  describe 'Nth day of week of month' do
202
202
  let(:ice_cube_model) do
203
- ::IceCube.from_cron(
203
+ ::IceCube::Schedule.from_cron(
204
204
  ::Date.new(2015, 1, 1),
205
205
  :repeat_weekday => '1#2'
206
206
  )
@@ -218,7 +218,7 @@ describe ::IceCubeCron do
218
218
 
219
219
  context 'input types' do
220
220
  it 'handles ::DateTime as input' do
221
- ice_cube_model = ::IceCube.from_cron(
221
+ ice_cube_model = ::IceCube::Schedule.from_cron(
222
222
  ::DateTime.new(2015, 5, 1),
223
223
  :repeat_day => '1',
224
224
  :repeat_interval => '2'
@@ -227,7 +227,7 @@ describe ::IceCubeCron do
227
227
  end
228
228
 
229
229
  it 'handles integer (epoch) as input' do
230
- ice_cube_model = ::IceCube.from_cron(
230
+ ice_cube_model = ::IceCube::Schedule.from_cron(
231
231
  1_430_438_400, # Fri, 01 May 2015 00:00:00 GMT
232
232
  :repeat_day => '1',
233
233
  :repeat_interval => '2'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ice_cube_cron
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Nichols
@@ -114,6 +114,7 @@ files:
114
114
  - lib/ice_cube_cron.rb
115
115
  - lib/ice_cube_cron/base.rb
116
116
  - lib/ice_cube_cron/expression_parser.rb
117
+ - lib/ice_cube_cron/extension.rb
117
118
  - lib/ice_cube_cron/rule_builder.rb
118
119
  - lib/ice_cube_cron/util.rb
119
120
  - lib/ice_cube_cron/version.rb