ice_t 0.0.7 → 0.0.8

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: 481cf81486c0337d36e8d288362cf9f1bcc014af
4
- data.tar.gz: 714bd7d33b6395a021b5c82ef9899d1bf1d38ff7
3
+ metadata.gz: 7c009725229f52d779eb425bacef4333fcb74025
4
+ data.tar.gz: 8f8fc915b744889a3bc4aec06bc06832f7f7490f
5
5
  SHA512:
6
- metadata.gz: b1ac6a8250be365dc49f9f1c56de9c6e0031890e2a985fb7f7aa621958ac8a3eb99f23ad2743f3ab844f9435f412d1a25f4eec8897415cf32e7b2c8a263a4172
7
- data.tar.gz: 1678686562bbd8cf649bd3ac6f94c3b36da118336eef50ac8e04297ddfd4c0d34b8f0af919122d6e4ab53e9d25fffc8bb9e47b449ebc0f16c823cd7f6c222015
6
+ metadata.gz: af9172f70fa10c41705a4fcca1039d3452f49449310818fc35e99378cfeafe0e518658a702c2b0cb0e35a5cbc69e00c8d5c2afd91410eb76d9e981b040c6d59c
7
+ data.tar.gz: e0c3689e2d634f63ee95e9bd20427722401baffd1fdfbca5713307ae4d754e99f736b3772e4efe99002de6bb63b1fd48b2d9634bdc04b225a7fa63bad55eb01f
data/README.md CHANGED
@@ -43,7 +43,10 @@ rule = IceT::Rule::Secondly.new # => every second
43
43
  ### Get time occurrences
44
44
 
45
45
  ```ruby
46
- rule.occurrences # => Array of times
46
+ rule.occurrences(2.days.ago, Time.now) # => Array of times
47
+
48
+ IceT::Rule::Daily.new(14).occurrences(1.year.ago, Time.now).first(5)
49
+
47
50
  ```
48
51
 
49
52
  ### Schedule
@@ -61,29 +64,68 @@ schedule.occurrences # => Merged occurrences
61
64
 
62
65
  ### Persistence
63
66
 
64
- Lets say you want to store and restore your Schedule. Do this:
67
+ Store and restore your rule:
65
68
 
66
69
  ```ruby
67
- json = schedule.to_json
68
- schedule = IceT::Schedule.from_json(json)
70
+
71
+ # JSON
72
+ rule = IceT::Rule::Daily.new(42)
73
+ json = rule.to_json
74
+ restored = IceT::Rule::Base.from_json(json)
75
+
76
+ # YAML
77
+ rule = IceT::Rule::Daily.new(42)
78
+ yaml = rule.to_yaml
79
+ restored = IceT::Rule::Base.from_yaml(yaml)
80
+
81
+ # Hash
82
+ rule = IceT::Rule::Daily.new(42)
83
+ hash = rule.to_hash
84
+ restored = IceT::Rule::Base.from_hash(hash)
85
+
69
86
  ```
70
87
 
71
- ## Tipps - section is under construction
72
88
 
73
- ### Sorting rules:
74
89
 
75
- [r2,r1,r3].sort.collect(&:interval)
90
+ Store and restore your Schedule:
76
91
 
77
- ### Comparing rules:
92
+ ```ruby
93
+ json = schedule.to_json
94
+ schedule = IceT::Schedule.from_json(json)
95
+ ```
96
+
97
+
98
+ ### Comparisons and sorting
78
99
 
79
100
  ```ruby
80
101
  IceT::Rule::Daily.new(1) < IceT::Rule::Monthly.new(1) # => true
81
102
  ```
82
103
 
83
104
  ```ruby
84
- r2.between?(r1, r3)
105
+ # compare different type of rules
106
+
107
+ minutely = IceT::Rule::Minutely.new(1)
108
+ hourly = IceT::Rule::Hourly.new(1)
109
+ daily = IceT::Rule::Daily.new(1)
110
+
111
+ hourly.between?(minutely, daily) # => true
112
+ minutely.between?(hourly, daily) # => false
113
+
114
+
115
+ # compare same type of rules
116
+
117
+ r1 = IceT::Rule::Daily.new(1)
118
+ r2 = IceT::Rule::Daily.new(2)
119
+ r3 = IceT::Rule::Daily.new(3)
120
+
121
+ r2.between?(r1, r2) # => true
122
+ r1.between?(r2, r3) # => false
123
+
124
+ # sort these rules
125
+
126
+ [r2,r1,r3].sort.collect(&:interval) # => [1, 2, 3]
127
+
85
128
  ```
86
- IceT::Rule::Daily.new(14).occurrences(1.year.ago, Time.now).first(5)
87
129
 
88
130
 
89
131
  ## License
@@ -1,54 +1,94 @@
1
+ #--
2
+ # Copyright (c) 2013 Christian Nennemann
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #++
23
+
1
24
  module IceT
2
25
  module Conversions
26
+ # module Helper
27
+ # module_function
28
+ # def recursive_instance_values(object)
29
+ # end
30
+ # end
31
+
32
+ module Common
33
+ module InstanceMethods
34
+ end
35
+ module ClassMethods
36
+ def from_yaml(yaml_string)
37
+ YAML::load(yaml_string)
38
+ end
39
+ end
40
+ end
41
+
3
42
  module Rule
4
43
 
5
44
  def self.included(klass)
6
45
  klass.extend ClassMethods
7
46
  end
8
-
47
+
9
48
  def to_hash
10
49
  self.instance_values.symbolize_keys
11
- end
50
+ end
12
51
 
13
52
  module ClassMethods
14
53
  def from_yaml(yaml_string)
15
- rule = YAML::load(yaml_string)
54
+ YAML::load(yaml_string)
55
+ end
56
+ def from_json(json_string)
57
+ hash = ActiveSupport::JSON.decode(json_string).symbolize_keys
58
+ self.from_hash(hash)
59
+ end
60
+ def from_hash(hash)
61
+ rule_class = hash[:rule]
62
+ interval = hash[:interval].to_i
63
+ eval(rule_class + ".new(#{interval})")
16
64
  end
17
65
  end
18
66
  end
19
67
 
20
68
  module Schedule
21
- def from_json(json_string)
22
- data = ActiveSupport::JSON.decode(json_string).symbolize_keys
23
-
24
- options = {
25
- start_time: data[:start_time].to_time,
26
- end_time: data[:end_time].to_time
27
- }
28
- schedule = self.new(options)
29
-
30
- data[:rules]["rules"].each{ |rule|
31
- rule_class = rule['rule']
32
- interval = rule['interval'].to_i
33
- at = rule['at']
34
- init = if at.nil?
35
- rule_class + ".new(#{interval})"
36
- else
37
- rule_class + ".new(#{interval}, '#{at}')"
38
- end
39
- obj_rule = eval(init)
40
- schedule.add_rule(obj_rule)
41
- }
42
-
43
- schedule
44
- end
45
-
46
-
47
- def from_yaml(yaml_string)
48
- schedule = YAML::load(yaml_string)
49
- return schedule if schedule.is_a?(IceT::Schedule)
69
+
70
+ def self.included(klass)
71
+ klass.extend ClassMethods
50
72
  end
51
73
 
74
+ module ClassMethods
75
+ def from_yaml(yaml_string)
76
+ YAML::load(yaml_string)
77
+ end
78
+
79
+ def from_json(json_string)
80
+ return unless json_string
81
+ data = ActiveSupport::JSON.decode(json_string).symbolize_keys
82
+ schedule = self.new(start_time: data[:start_time].to_time, end_time: data[:end_time].to_time)
83
+ data[:rules]["rules"].each{ |rule|
84
+ schedule.add_rule(
85
+ IceT::Rule::Base.from_json(rule.to_json)
86
+ )
87
+ }
88
+ schedule
89
+ end
90
+ end
52
91
  end
92
+
53
93
  end
54
94
  end
@@ -1,3 +1,26 @@
1
+ #--
2
+ # Copyright (c) 2013 Christian Nennemann
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #++
23
+
1
24
  module IceT
2
25
  class DuplicateRuleException < StandardError; end
3
26
  end
data/lib/ice_t/rule.rb CHANGED
@@ -1,3 +1,26 @@
1
+ #--
2
+ # Copyright (c) 2013 Christian Nennemann
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #++
23
+
1
24
  module IceT
2
25
  module Rule
3
26
  end
@@ -1,3 +1,26 @@
1
+ #--
2
+ # Copyright (c) 2013 Christian Nennemann
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #++
23
+
1
24
  module IceT
2
25
  module Rule
3
26
  class Base
@@ -12,44 +35,34 @@ module IceT
12
35
  include IceT::Conversions::Rule
13
36
 
14
37
  attr_reader :interval
15
- attr_reader :at
16
38
 
17
- def initialize(interval = 1, at_str = nil)
39
+ def initialize(interval = 1)
18
40
  raise ArgumentError.new('Positive integer required') if interval.nil? ||
19
41
  interval.to_i < 1 ||
20
42
  interval % 1 != 0
21
- @interval = interval
22
- @at = at_str
23
43
  @rule = self.class.name
24
- self.at = at_str unless @at.nil?
25
- end
26
-
27
- # set time information
28
- def at=(str)
29
- return if str.nil?
30
- if Time.parse(str.to_s)
31
- @at = str.to_s
32
- end
44
+ @interval = interval
33
45
  end
34
46
 
35
47
  include Comparable
36
48
  def <=>(other)
37
- case
38
- when self.class == other.class &&
39
- self.interval == other.interval
40
- 0
41
- when self.class == other.class &&
42
- self.interval < other.interval
43
- -1
44
- when self.class == other.class &&
45
- self.interval > other.interval
46
- +1
47
- when self.class.to_i < other.class.to_i
48
- -1
49
- when self.class.to_i > other.class.to_i
50
- +1
49
+ return unless other.class.respond_to?(:to_i)
50
+ if self.class == other.class
51
+ case
52
+ when self.interval == other.interval
53
+ 0
54
+ when self.interval < other.interval
55
+ -1
56
+ when self.interval > other.interval
57
+ +1
58
+ end
51
59
  else
52
- nil
60
+ case
61
+ when self.class.to_i < other.class.to_i
62
+ -1
63
+ when self.class.to_i > other.class.to_i
64
+ +1
65
+ end
53
66
  end
54
67
  end
55
68
 
@@ -60,12 +73,6 @@ module IceT
60
73
  }
61
74
  end
62
75
 
63
- # private
64
- # def at_adjusted_time(time)
65
- # unless @at.nil?
66
- # t = Time.parse(@at)
67
- # end
68
- # end
69
76
  end
70
77
  end
71
78
  end
@@ -1,3 +1,26 @@
1
+ #--
2
+ # Copyright (c) 2013 Christian Nennemann
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #++
23
+
1
24
  module IceT
2
25
  module Rule
3
26
  class Daily < Base
@@ -5,13 +28,6 @@ module IceT
5
28
  def to_i; 1.day.to_i end
6
29
  def unit; :days end
7
30
  end
8
-
9
- def to_s
10
- word = (@interval.eql?(2))? 'zweiten' : @interval
11
- # "jeden #{@interval} tage"
12
- "jeden #{word} tag"
13
- end
14
-
15
31
  end
16
32
  end
17
33
  end
@@ -1,3 +1,26 @@
1
+ #--
2
+ # Copyright (c) 2013 Christian Nennemann
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #++
23
+
1
24
  module IceT
2
25
  module Rule
3
26
  class Hourly < Base
@@ -1,3 +1,26 @@
1
+ #--
2
+ # Copyright (c) 2013 Christian Nennemann
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #++
23
+
1
24
  module IceT
2
25
  module Rule
3
26
  class Minutely < Base
@@ -1,3 +1,26 @@
1
+ #--
2
+ # Copyright (c) 2013 Christian Nennemann
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #++
23
+
1
24
  module IceT
2
25
  module Rule
3
26
  class Monthly < Base
@@ -1,3 +1,26 @@
1
+ #--
2
+ # Copyright (c) 2013 Christian Nennemann
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #++
23
+
1
24
  require 'forwardable'
2
25
 
3
26
  module IceT
@@ -1,3 +1,26 @@
1
+ #--
2
+ # Copyright (c) 2013 Christian Nennemann
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #++
23
+
1
24
  module IceT
2
25
  module Rule
3
26
  class Secondly < Base
@@ -1,3 +1,26 @@
1
+ #--
2
+ # Copyright (c) 2013 Christian Nennemann
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #++
23
+
1
24
  module IceT
2
25
  module Rule
3
26
  class Weekly < Base
@@ -1,3 +1,26 @@
1
+ #--
2
+ # Copyright (c) 2013 Christian Nennemann
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #++
23
+
1
24
  module IceT
2
25
  module Rule
3
26
  class Yearly < Base
@@ -1,3 +1,26 @@
1
+ #--
2
+ # Copyright (c) 2013 Christian Nennemann
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #++
23
+
1
24
  require 'forwardable'
2
25
 
3
26
  module IceT
@@ -8,7 +31,7 @@ module IceT
8
31
  def_delegator :@rules, :remove, :remove_rule
9
32
  def_delegator :@rules, :rules, :rules
10
33
 
11
- extend IceT::Conversions::Schedule
34
+ include IceT::Conversions::Schedule
12
35
 
13
36
  attr_reader :start_time
14
37
  attr_reader :end_time
@@ -1,3 +1,26 @@
1
+ #--
2
+ # Copyright (c) 2013 Christian Nennemann
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #++
23
+
1
24
  module IceT
2
25
  module TimeHelper
3
26
  module_function
data/lib/ice_t/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module IceT
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
@@ -63,6 +63,10 @@ describe IceT::Rule::Base do
63
63
  }
64
64
  end
65
65
  }
66
+
67
+ subject { IceT::Rule::Daily.new(1) }
68
+ it { expect{subject < "a"}.to raise_error }
69
+ it { expect{subject > 1}.to raise_error }
66
70
  end
67
71
 
68
72
 
@@ -78,18 +82,6 @@ describe IceT::Rule::Base do
78
82
  it { expect{subject.class.new("a")}.to raise_error }
79
83
  end
80
84
  end
81
-
82
- describe 'param: at' do
83
- context 'when valid' do
84
- it { expect{subject.class.new(1, "4pm")}.not_to raise_error }
85
- it { expect{subject.class.new(1, nil)}.not_to raise_error }
86
- end
87
- context 'when invalid' do
88
- it { expect{subject.class.new(1, "")}.to raise_error }
89
- it { expect{subject.class.new(1, -1)}.to raise_error }
90
- it { expect{subject.class.new(1, "a")}.to raise_error }
91
- end
92
- end
93
85
  end
94
86
 
95
87
  context 'respond_to?' do
@@ -1,6 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe IceT::Schedule do
4
+ let!(:klass) { IceT::Schedule }
4
5
  let!(:start_time) { Time.now }
5
6
  let!(:end_time) { Time.now + 2.months }
6
7
  let!(:schedule) { IceT::Schedule.new(start_time: start_time, end_time: end_time) }
@@ -30,11 +31,13 @@ describe IceT::Schedule do
30
31
  end
31
32
 
32
33
  describe '#to_json' do
33
- pending
34
+ it { expect(subject).to respond_to(:to_json) }
35
+ it { expect(subject.to_json).to be_an(String) }
34
36
  end
35
37
 
36
38
  describe '#to_yaml' do
37
- pending
39
+ it { expect(subject).to respond_to(:to_yaml) }
40
+ it { expect(subject.to_json).to be_an(String) }
38
41
  end
39
42
 
40
43
  describe '::from_json' do
@@ -42,7 +45,6 @@ describe IceT::Schedule do
42
45
  before do
43
46
  schedule.add_rule(daily_rule)
44
47
  schedule.add_rule(monthly_rule)
45
- schedule.add_rule(IceT::Rule::Daily.new(12, "4pm"))
46
48
  end
47
49
  let(:json) { schedule.to_json }
48
50
  let(:object) { IceT::Schedule.from_json(json) }
@@ -63,8 +65,20 @@ describe IceT::Schedule do
63
65
  end
64
66
  end
65
67
 
66
- describe '::from_yaml' do
67
- pending
68
+ describe '#to_hash' do
69
+ it "does respond_to :to_hash" do
70
+ pending "Conversions::Helper.recursive_instance_values"
71
+ expect(subject).to respond_to(:to_hash)
72
+ end
73
+ end
74
+
75
+ describe '::from_yaml' do
76
+ it { expect(subject).to respond_to(:to_yaml) }
77
+ it "does contain same values as before" do
78
+ pending "serialize Rule::Repository" do
79
+ expect(IceT::Schedule.from_yaml(schedule.to_yaml) == schedule).to be_true
80
+ end
81
+ end
68
82
  end
69
83
 
70
84
  end
@@ -1,4 +1,5 @@
1
1
  shared_examples 'a rule' do
2
+ let(:rule){ klass.new(1) }
2
3
 
3
4
  describe '::to_i' do
4
5
  it { expect(klass).to respond_to(:to_i) }
@@ -10,7 +11,6 @@ shared_examples 'a rule' do
10
11
  describe '#occurrences' do
11
12
  it { expect(klass.new).to respond_to(:occurrences) }
12
13
 
13
- let(:rule){ klass.new(1) }
14
14
  let(:start_time){ Time.now }
15
15
  let(:duration){ eval("2.#{klass.unit}") }
16
16
  let(:end_time){ start_time + duration }
@@ -24,14 +24,19 @@ shared_examples 'a rule' do
24
24
  end
25
25
  end
26
26
 
27
+
27
28
  describe '::from_json' do
28
- pending
29
- #it { expect(klass).to respond_to(:from_json) }
29
+ it { expect(klass).to respond_to(:from_json) }
30
+ it { expect(klass.from_json(rule.to_json) == rule).to be_true }
31
+ end
32
+ describe '::from_hash' do
33
+ it { expect(klass).to respond_to(:from_hash) }
34
+ it { expect(klass.from_hash(rule.to_hash) == rule).to be_true }
30
35
  end
31
36
 
32
37
  describe '::from_yaml' do
33
- pending
34
- #it { expect(klass).to respond_to(:from_yaml) }
38
+ it { expect(klass).to respond_to(:from_yaml) }
39
+ it { expect(klass.from_yaml(rule.to_yaml) == rule).to be_true }
35
40
  end
36
41
 
37
42
  describe '#to_json' do
@@ -46,9 +51,4 @@ shared_examples 'a rule' do
46
51
  it { expect(klass.new).to respond_to(:to_hash) }
47
52
  end
48
53
 
49
- describe '#@at' do
50
- it {expect(klass.new(1, "4pm").at).to eql("4pm")}
51
- end
52
-
53
-
54
54
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ice_t
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christian Nennemann
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-08 00:00:00.000000000 Z
11
+ date: 2013-12-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport