chrono 0.0.6 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/README.md +1 -1
- data/lib/chrono/fields/base.rb +26 -0
- data/lib/chrono/version.rb +1 -1
- data/spec/chrono/iterator_spec.rb +16 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b2654829b86a6c6e8ad37744e19fc96408a5ac9f
|
4
|
+
data.tar.gz: a50cb68f2dcd05bafd92ce0c2f6ff6cc5df4e0f6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6d32b10ee846d5a185dcff6a05bb0dc11deee5cbb58ac9e68d32032fe26d04e80708be98da15b574abe7016d39059b19aba2685a73584ce3664859558a35a519
|
7
|
+
data.tar.gz: 81d639646d8c41744af982fc1bb616df02fd3d3514be8e09897b2306253f489e83ed8da3bb0c90fc013225c53e5c5fee885f73ff859227a43ad9ee6ae25e7543
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
data/lib/chrono/fields/base.rb
CHANGED
@@ -1,6 +1,15 @@
|
|
1
1
|
module Chrono
|
2
2
|
module Fields
|
3
3
|
class Base
|
4
|
+
class InvalidField < StandardError
|
5
|
+
attr_reader :source
|
6
|
+
|
7
|
+
def initialize(message, source)
|
8
|
+
super("#{message}: #{source}")
|
9
|
+
@source = source
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
4
13
|
attr_reader :source
|
5
14
|
|
6
15
|
def initialize(source)
|
@@ -11,6 +20,7 @@ module Chrono
|
|
11
20
|
if has_multiple_elements?
|
12
21
|
fields.map(&:to_a).flatten.uniq.sort
|
13
22
|
else
|
23
|
+
validate!
|
14
24
|
lower.step(upper, step).to_a.sort
|
15
25
|
end
|
16
26
|
end
|
@@ -21,6 +31,22 @@ module Chrono
|
|
21
31
|
source.gsub("*", "#{range.first}-#{range.last}")
|
22
32
|
end
|
23
33
|
|
34
|
+
def validate!
|
35
|
+
unless match_data
|
36
|
+
raise InvalidField.new('Unparsable field', source)
|
37
|
+
end
|
38
|
+
|
39
|
+
if lower < range.begin || range.end < upper
|
40
|
+
raise InvalidField.new('The field is out-of-range', source)
|
41
|
+
end
|
42
|
+
|
43
|
+
if upper < lower
|
44
|
+
raise InvalidField.new('The range is evaluated to empty', source)
|
45
|
+
end
|
46
|
+
|
47
|
+
true
|
48
|
+
end
|
49
|
+
|
24
50
|
def lower
|
25
51
|
@lower ||= match_data[1].to_i
|
26
52
|
end
|
data/lib/chrono/version.rb
CHANGED
@@ -27,6 +27,22 @@ describe Chrono::Iterator do
|
|
27
27
|
now = Time.parse(from)
|
28
28
|
described_class.new(source, now: now).next.should == Time.parse(to)
|
29
29
|
end
|
30
|
+
|
31
|
+
it 'raises error when empty range is given' do
|
32
|
+
expect { described_class.new('5-0 * * * *').next }.to raise_error(Chrono::Fields::Base::InvalidField)
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'raises error when too large upper is given' do
|
36
|
+
expect { described_class.new('5-60 * * * *').next }.to raise_error(Chrono::Fields::Base::InvalidField)
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'raises error when too low lower is given' do
|
40
|
+
expect { described_class.new('* * 0 * *').next }.to raise_error(Chrono::Fields::Base::InvalidField)
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'raises error when unparsable field is given' do
|
44
|
+
expect { described_class.new('a-z * * * *').next }.to raise_error(Chrono::Fields::Base::InvalidField)
|
45
|
+
end
|
30
46
|
end
|
31
47
|
end
|
32
48
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chrono
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryo Nakamura
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-09-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|