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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a42cc20a3ed6750c544e39bd47e14ace15f36d5b
4
- data.tar.gz: c55208bf4082532883e069f3c18a69332641f288
3
+ metadata.gz: b2654829b86a6c6e8ad37744e19fc96408a5ac9f
4
+ data.tar.gz: a50cb68f2dcd05bafd92ce0c2f6ff6cc5df4e0f6
5
5
  SHA512:
6
- metadata.gz: 86f6bb35356917719c2fcc4bb467ea81dd2d11b4ea770f4b04cf78d3ad1f727c4a3d591adf54d5b9014b4f2d026802ed1858e0b609985b91f21bc7716b8c9cb8
7
- data.tar.gz: 8455ebc6191819ed3ec105462fbc36dd98cef6f4635f73ad7e16649d377f5ea2ee552c1fc3a18317d731c5ac21f6e1681fe8ef3c9f9cf8b688da6e992b624114
6
+ metadata.gz: 6d32b10ee846d5a185dcff6a05bb0dc11deee5cbb58ac9e68d32032fe26d04e80708be98da15b574abe7016d39059b19aba2685a73584ce3664859558a35a519
7
+ data.tar.gz: 81d639646d8c41744af982fc1bb616df02fd3d3514be8e09897b2306253f489e83ed8da3bb0c90fc013225c53e5c5fee885f73ff859227a43ad9ee6ae25e7543
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## 0.1.0
2
+ - Raise errors on invalid fields (thx @eagletmt)
3
+
1
4
  ## 0.0.6
2
5
  - Support ActiveSupport 3 and 4
3
6
 
data/README.md CHANGED
@@ -37,7 +37,7 @@ for more details.
37
37
  ```
38
38
  * * * * *
39
39
  T T T T T
40
- | | | | `- wday --- 0 .. 6
40
+ | | | | `- wday --- 0 .. 6 (0 = Sunday)
41
41
  | | | `--- month -- 1 .. 12
42
42
  | | `----- day ---- 1 .. 31
43
43
  | `------- hour --- 0 .. 23
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Chrono
2
- VERSION = "0.0.6"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -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.6
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-03-30 00:00:00.000000000 Z
11
+ date: 2015-09-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport