ice_t 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -1
- data/lib/ice_t/conversions.rb +18 -1
- data/lib/ice_t/rule/base.rb +3 -1
- data/lib/ice_t/version.rb +1 -1
- data/spec/rules/base_spec.rb +6 -0
- data/spec/support/shared_examples/rule_example.rb +4 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 481cf81486c0337d36e8d288362cf9f1bcc014af
|
4
|
+
data.tar.gz: 714bd7d33b6395a021b5c82ef9899d1bf1d38ff7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b1ac6a8250be365dc49f9f1c56de9c6e0031890e2a985fb7f7aa621958ac8a3eb99f23ad2743f3ab844f9435f412d1a25f4eec8897415cf32e7b2c8a263a4172
|
7
|
+
data.tar.gz: 1678686562bbd8cf649bd3ac6f94c3b36da118336eef50ac8e04297ddfd4c0d34b8f0af919122d6e4ab53e9d25fffc8bb9e47b449ebc0f16c823cd7f6c222015
|
data/README.md
CHANGED
@@ -80,8 +80,10 @@ schedule = IceT::Schedule.from_json(json)
|
|
80
80
|
IceT::Rule::Daily.new(1) < IceT::Rule::Monthly.new(1) # => true
|
81
81
|
```
|
82
82
|
|
83
|
+
```ruby
|
83
84
|
r2.between?(r1, r3)
|
84
|
-
|
85
|
+
```
|
86
|
+
IceT::Rule::Daily.new(14).occurrences(1.year.ago, Time.now).first(5)
|
85
87
|
|
86
88
|
|
87
89
|
## License
|
data/lib/ice_t/conversions.rb
CHANGED
@@ -1,5 +1,22 @@
|
|
1
1
|
module IceT
|
2
2
|
module Conversions
|
3
|
+
module Rule
|
4
|
+
|
5
|
+
def self.included(klass)
|
6
|
+
klass.extend ClassMethods
|
7
|
+
end
|
8
|
+
|
9
|
+
def to_hash
|
10
|
+
self.instance_values.symbolize_keys
|
11
|
+
end
|
12
|
+
|
13
|
+
module ClassMethods
|
14
|
+
def from_yaml(yaml_string)
|
15
|
+
rule = YAML::load(yaml_string)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
3
20
|
module Schedule
|
4
21
|
def from_json(json_string)
|
5
22
|
data = ActiveSupport::JSON.decode(json_string).symbolize_keys
|
@@ -11,7 +28,7 @@ module IceT
|
|
11
28
|
schedule = self.new(options)
|
12
29
|
|
13
30
|
data[:rules]["rules"].each{ |rule|
|
14
|
-
rule_class = rule['
|
31
|
+
rule_class = rule['rule']
|
15
32
|
interval = rule['interval'].to_i
|
16
33
|
at = rule['at']
|
17
34
|
init = if at.nil?
|
data/lib/ice_t/rule/base.rb
CHANGED
@@ -9,6 +9,8 @@ module IceT
|
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
|
+
include IceT::Conversions::Rule
|
13
|
+
|
12
14
|
attr_reader :interval
|
13
15
|
attr_reader :at
|
14
16
|
|
@@ -18,7 +20,7 @@ module IceT
|
|
18
20
|
interval % 1 != 0
|
19
21
|
@interval = interval
|
20
22
|
@at = at_str
|
21
|
-
@
|
23
|
+
@rule = self.class.name
|
22
24
|
self.at = at_str unless @at.nil?
|
23
25
|
end
|
24
26
|
|
data/lib/ice_t/version.rb
CHANGED
data/spec/rules/base_spec.rb
CHANGED
@@ -42,6 +42,10 @@ shared_examples 'a rule' do
|
|
42
42
|
it { expect(klass.new).to respond_to(:to_yaml) }
|
43
43
|
end
|
44
44
|
|
45
|
+
describe '#to_hash' do
|
46
|
+
it { expect(klass.new).to respond_to(:to_hash) }
|
47
|
+
end
|
48
|
+
|
45
49
|
describe '#@at' do
|
46
50
|
it {expect(klass.new(1, "4pm").at).to eql("4pm")}
|
47
51
|
end
|