ice_t 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.travis.yml +3 -0
- data/CHANGELOG.md +0 -0
- data/Gemfile +4 -0
- data/Guardfile +12 -0
- data/LICENSE +20 -0
- data/LICENSE.txt +22 -0
- data/README.md +37 -0
- data/Rakefile +5 -0
- data/ice_t.gemspec +31 -0
- data/lib/ice_t.rb +21 -0
- data/lib/ice_t/conversions.rb +37 -0
- data/lib/ice_t/exceptions.rb +3 -0
- data/lib/ice_t/rule.rb +13 -0
- data/lib/ice_t/rule/base.rb +69 -0
- data/lib/ice_t/rule/daily.rb +17 -0
- data/lib/ice_t/rule/hourly.rb +10 -0
- data/lib/ice_t/rule/minutely.rb +10 -0
- data/lib/ice_t/rule/monthly.rb +10 -0
- data/lib/ice_t/rule/repository.rb +25 -0
- data/lib/ice_t/rule/yearly.rb +10 -0
- data/lib/ice_t/schedule.rb +39 -0
- data/lib/ice_t/time_helper.rb +16 -0
- data/lib/ice_t/version.rb +3 -0
- data/lib/locales/en.yml +3 -0
- data/spec/exceptions_spec.rb +11 -0
- data/spec/rules/base_spec.rb +40 -0
- data/spec/rules/daily_rule_spec.rb +6 -0
- data/spec/rules/hourly_rule_spec.rb +6 -0
- data/spec/rules/minutely_rule_spec.rb +6 -0
- data/spec/rules/monthly_rule_spec.rb +33 -0
- data/spec/rules/rules_repository_spec.rb +34 -0
- data/spec/rules/yearly_rule_spec.rb +6 -0
- data/spec/schedule_spec.rb +70 -0
- data/spec/spec_helper.rb +16 -0
- data/spec/support/shared_examples/rule_example.rb +92 -0
- metadata +189 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 43afa790b32508abdc490d1390c56a5411c944dc
|
4
|
+
data.tar.gz: 2847c139721b59a32e3041a1b3acacc54df70684
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 994528d6ea3d8c9c487f2df182a3a2cc9a1449bf71dd218a0465a32227ae4b737e0685689be90b2ce7eb4a4a0544cb93591e38ea9d2271dc653f3164c75c2c94
|
7
|
+
data.tar.gz: 0db1cbe1e52a19b847f6d6c89cb67321457e4f1f8112a0ceabc4ccaa4adfdf68c677a0fbe123a8f8885788555910688e3e36cdcf36659e8b40c520addccb60bb
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
File without changes
|
data/Gemfile
ADDED
data/Guardfile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
guard :rspec do
|
2
|
+
watch(%r{^spec/.+_spec\.rb$})
|
3
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
4
|
+
watch('spec/spec_helper.rb') { "spec" }
|
5
|
+
|
6
|
+
# Capybara features specs
|
7
|
+
watch(%r{^app/views/(.+)/.*\.(erb|haml|slim)$}) { |m| "spec/features/#{m[1]}_spec.rb" }
|
8
|
+
|
9
|
+
# Turnip features and steps
|
10
|
+
watch(%r{^spec/acceptance/(.+)\.feature$})
|
11
|
+
watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
|
12
|
+
end
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2013 Christian Nennemann
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
7
|
+
the Software without restriction, including without limitation the rights to
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Christian Nennemann
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# IceT
|
2
|
+
|
3
|
+
[![Code Climate](https://codeclimate.com/github/XORwell/ice_t.png)](https://codeclimate.com/github/XORwell/ice_t)
|
4
|
+
[![Build Status](https://travis-ci.org/XORwell/ice_t.png)](https://travis-ci.org/XORwell/ice_t)
|
5
|
+
|
6
|
+
TODO: Write a gem description
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
gem 'ice_t'
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install ice_t
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
TODO: Write usage instructions here
|
25
|
+
|
26
|
+
|
27
|
+
## Tipps
|
28
|
+
|
29
|
+
### Sorting rules:
|
30
|
+
|
31
|
+
[r2,r1,r3].sort.collect(&:interval)
|
32
|
+
|
33
|
+
### Comparing comparing:
|
34
|
+
|
35
|
+
daily(1) < daily(2)
|
36
|
+
|
37
|
+
r2.between?(r1, r3)
|
data/Rakefile
ADDED
data/ice_t.gemspec
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'ice_t/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "ice_t"
|
8
|
+
spec.version = IceT::VERSION
|
9
|
+
spec.authors = ["Christian Nennemann"]
|
10
|
+
spec.email = ["christian.nennemann@gmail.com"]
|
11
|
+
spec.description = %q{IceT is a ruby library for handling repeated events}
|
12
|
+
spec.summary = %q{Ruby Time Recurrence}
|
13
|
+
spec.homepage = "https://github.com/XORwell/IceT"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "activesupport", ">= 4.0.0"
|
22
|
+
#spec.add_dependency "i18n", ">= 0.6.5"
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
25
|
+
spec.add_development_dependency "rake"
|
26
|
+
spec.add_development_dependency "rspec", "~> 2.13"
|
27
|
+
spec.add_development_dependency "turnip"
|
28
|
+
spec.add_development_dependency "guard"
|
29
|
+
spec.add_development_dependency "guard-rspec"
|
30
|
+
|
31
|
+
end
|
data/lib/ice_t.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require "ice_t/version"
|
2
|
+
|
3
|
+
# TODO: be more specific instead including all..
|
4
|
+
require 'active_support/all'
|
5
|
+
|
6
|
+
|
7
|
+
module IceT
|
8
|
+
I18n.load_path += Dir[File.expand_path('../locales/*{rb,yml}', __FILE__)]
|
9
|
+
|
10
|
+
require 'ice_t/exceptions'
|
11
|
+
|
12
|
+
require 'ice_t/time_helper'
|
13
|
+
|
14
|
+
require 'ice_t/conversions'
|
15
|
+
require 'ice_t/rule'
|
16
|
+
require 'ice_t/schedule'
|
17
|
+
|
18
|
+
# module Rule
|
19
|
+
# autoload :Repository, 'ice_t/rule/repository'
|
20
|
+
# end
|
21
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module IceT
|
2
|
+
module Conversions
|
3
|
+
module Schedule
|
4
|
+
def from_json(json_string)
|
5
|
+
data = ActiveSupport::JSON.decode(json_string).symbolize_keys
|
6
|
+
|
7
|
+
options = {
|
8
|
+
start_time: data[:start_time].to_time,
|
9
|
+
end_time: data[:end_time].to_time
|
10
|
+
}
|
11
|
+
schedule = self.new(options)
|
12
|
+
|
13
|
+
data[:rules]["rules"].each{ |rule|
|
14
|
+
rule_class = rule['export_class_name']
|
15
|
+
interval = rule['interval'].to_i
|
16
|
+
at = rule['at']
|
17
|
+
init = if at.nil?
|
18
|
+
rule_class + ".new(#{interval})"
|
19
|
+
else
|
20
|
+
rule_class + ".new(#{interval}, '#{at}')"
|
21
|
+
end
|
22
|
+
obj_rule = eval(init)
|
23
|
+
schedule.add_rule(obj_rule)
|
24
|
+
}
|
25
|
+
|
26
|
+
schedule
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
def from_yaml(yaml_string)
|
31
|
+
schedule = YAML::load(yaml_string)
|
32
|
+
return schedule if schedule.is_a?(IceT::Schedule)
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/lib/ice_t/rule.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
module IceT
|
2
|
+
module Rule
|
3
|
+
end
|
4
|
+
end
|
5
|
+
|
6
|
+
require 'ice_t/rule/base'
|
7
|
+
require 'ice_t/rule/repository'
|
8
|
+
require 'ice_t/rule/minutely'
|
9
|
+
require 'ice_t/rule/hourly'
|
10
|
+
require 'ice_t/rule/daily'
|
11
|
+
require 'ice_t/rule/monthly'
|
12
|
+
require 'ice_t/rule/yearly'
|
13
|
+
|
@@ -0,0 +1,69 @@
|
|
1
|
+
module IceT
|
2
|
+
module Rule
|
3
|
+
class Base
|
4
|
+
|
5
|
+
class << self
|
6
|
+
include Comparable
|
7
|
+
def <=>(other)
|
8
|
+
self.to_i <=> other.to_i
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
attr_reader :interval
|
13
|
+
attr_reader :at
|
14
|
+
|
15
|
+
def initialize(interval = 1, at_str = nil)
|
16
|
+
raise ArgumentError.new('Positive integer required') if interval.nil? ||
|
17
|
+
interval.to_i < 1 ||
|
18
|
+
interval % 1 != 0
|
19
|
+
@interval = interval
|
20
|
+
@at = at_str
|
21
|
+
@export_class_name = self.class.name
|
22
|
+
self.at = at_str unless @at.nil?
|
23
|
+
end
|
24
|
+
|
25
|
+
# set time information
|
26
|
+
def at=(str)
|
27
|
+
return if str.nil?
|
28
|
+
if Time.parse(str.to_s)
|
29
|
+
@at = str.to_s
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
include Comparable
|
34
|
+
def <=>(other)
|
35
|
+
case
|
36
|
+
when self.class == other.class &&
|
37
|
+
self.interval == other.interval
|
38
|
+
0
|
39
|
+
when self.class == other.class &&
|
40
|
+
self.interval < other.interval
|
41
|
+
-1
|
42
|
+
when self.class == other.class &&
|
43
|
+
self.interval > other.interval
|
44
|
+
+1
|
45
|
+
when self.class.to_i < other.class.to_i
|
46
|
+
-1
|
47
|
+
when self.class.to_i > other.class.to_i
|
48
|
+
+1
|
49
|
+
else
|
50
|
+
nil
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def occurrences(start_time, end_time)
|
55
|
+
diff = IceT::TimeHelper.diff_by_unit(start_time, end_time, self.class.unit)
|
56
|
+
(1..diff).step(self.interval).map { |i|
|
57
|
+
start_time.advance(self.class.unit => i)
|
58
|
+
}
|
59
|
+
end
|
60
|
+
|
61
|
+
# private
|
62
|
+
# def at_adjusted_time(time)
|
63
|
+
# unless @at.nil?
|
64
|
+
# t = Time.parse(@at)
|
65
|
+
# end
|
66
|
+
# end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module IceT
|
2
|
+
module Rule
|
3
|
+
class Daily < Base
|
4
|
+
class << self
|
5
|
+
def to_i; 1.day.to_i end
|
6
|
+
def unit; :days end
|
7
|
+
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
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'forwardable'
|
2
|
+
|
3
|
+
module IceT
|
4
|
+
module Rule
|
5
|
+
class Repository
|
6
|
+
extend Forwardable
|
7
|
+
def_delegators :@rules, :empty?, :size, :first, :last, :collect
|
8
|
+
|
9
|
+
attr_reader :rules
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
@rules = []
|
13
|
+
end
|
14
|
+
|
15
|
+
def add(rule)
|
16
|
+
@rules << rule unless rule.nil?
|
17
|
+
end
|
18
|
+
|
19
|
+
def remove(rule)
|
20
|
+
@rules.delete(rule)
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'forwardable'
|
2
|
+
|
3
|
+
module IceT
|
4
|
+
class Schedule
|
5
|
+
|
6
|
+
extend Forwardable
|
7
|
+
def_delegator :@rules, :add, :add_rule
|
8
|
+
def_delegator :@rules, :remove, :remove_rule
|
9
|
+
def_delegator :@rules, :rules, :rules
|
10
|
+
|
11
|
+
extend IceT::Conversions::Schedule
|
12
|
+
|
13
|
+
attr_reader :start_time
|
14
|
+
attr_reader :end_time
|
15
|
+
|
16
|
+
def initialize(opts={})
|
17
|
+
opts = {
|
18
|
+
start_time: nil,
|
19
|
+
end_time: nil
|
20
|
+
}.merge(opts)
|
21
|
+
@start_time = opts[:start_time]
|
22
|
+
@end_time = opts[:end_time]
|
23
|
+
|
24
|
+
@rules = IceT::Rule::Repository.new
|
25
|
+
end
|
26
|
+
|
27
|
+
def occurrences
|
28
|
+
return [] if @rules.empty?
|
29
|
+
|
30
|
+
# TODO: better error message
|
31
|
+
fail('this needs start_time and end_time') if @start_time.nil? && @end_time.nil?
|
32
|
+
|
33
|
+
@rules.collect{ |rule|
|
34
|
+
rule.occurrences(@start_time, @end_time)
|
35
|
+
}.flatten
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module IceT
|
2
|
+
module TimeHelper
|
3
|
+
module_function
|
4
|
+
#
|
5
|
+
# Returns diff of two date by given unit
|
6
|
+
# @param Time start_time
|
7
|
+
# @param Time end_time
|
8
|
+
# @param Symbol unit
|
9
|
+
# @param Boolean round
|
10
|
+
# @return Integer|Float diff
|
11
|
+
def diff_by_unit(start_time, end_time, unit = :days, round = true)
|
12
|
+
diff = ((end_time - start_time) / eval("1.#{unit}"))
|
13
|
+
diff = (round) ? diff.round : diff
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/locales/en.yml
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe IceT::Rule::Base do
|
4
|
+
|
5
|
+
describe '.new' do
|
6
|
+
describe 'param: interval' do
|
7
|
+
context 'when valid' do
|
8
|
+
it { expect{subject.class.new(1)}.not_to raise_error }
|
9
|
+
it { expect{subject.class.new()}.not_to raise_error }
|
10
|
+
end
|
11
|
+
context 'when invalid' do
|
12
|
+
it { expect{subject.class.new(-1)}.to raise_error }
|
13
|
+
it { expect{subject.class.new(1.2)}.to raise_error }
|
14
|
+
it { expect{subject.class.new("a")}.to raise_error }
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe 'param: at' do
|
19
|
+
context 'when valid' do
|
20
|
+
it { expect{subject.class.new(1, "4pm")}.not_to raise_error }
|
21
|
+
it { expect{subject.class.new(1, nil)}.not_to raise_error }
|
22
|
+
end
|
23
|
+
context 'when invalid' do
|
24
|
+
it { expect{subject.class.new(1, "")}.to raise_error }
|
25
|
+
it { expect{subject.class.new(1, -1)}.to raise_error }
|
26
|
+
it { expect{subject.class.new(1, "a")}.to raise_error }
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'respond_to?' do
|
32
|
+
operators = ['==', '<', '>', '<=', '>=']
|
33
|
+
operators.each{ |operator|
|
34
|
+
describe operator do
|
35
|
+
it { expect(subject.class.new.respond_to?(operator.to_sym)).to be_true }
|
36
|
+
end
|
37
|
+
}
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe IceT::Rule::Monthly do
|
4
|
+
|
5
|
+
let(:klass) { IceT::Rule::Monthly }
|
6
|
+
it_behaves_like "a rule"
|
7
|
+
|
8
|
+
let!(:interval) { 1 }
|
9
|
+
let!(:start_time) { 1.year.ago }
|
10
|
+
let!(:end_time) { Time.now }
|
11
|
+
let(:rule) { IceT::Rule::Monthly.new(interval) }
|
12
|
+
|
13
|
+
|
14
|
+
describe "#occurrences" do
|
15
|
+
|
16
|
+
subject { rule.occurrences(start_time, end_time) }
|
17
|
+
|
18
|
+
it "returns an array" do
|
19
|
+
expect(subject).to be_an(Array)
|
20
|
+
end
|
21
|
+
|
22
|
+
context "one year ago until now" do
|
23
|
+
it "returns an array with 12 elements" do
|
24
|
+
expect(subject.size).to eql(12)
|
25
|
+
end
|
26
|
+
it "contains end_time as last element" do
|
27
|
+
expect(subject.last.to_date).to eql(end_time.to_date)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe IceT::Rule::Repository do
|
4
|
+
let(:repo) { IceT::Rule::Repository.new }
|
5
|
+
let!(:rule_01) { IceT::Rule::Daily.new(1) }
|
6
|
+
let!(:rule_02) { IceT::Rule::Daily.new(2) }
|
7
|
+
let!(:rule_03) { IceT::Rule::Daily.new(3) }
|
8
|
+
|
9
|
+
describe '#rules' do
|
10
|
+
it "returns an array" do
|
11
|
+
expect(repo.rules).to be_an(Array)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '#add' do
|
16
|
+
it "adds a rule" do
|
17
|
+
repo.add(rule_01)
|
18
|
+
expect(repo.rules.size).to eql(1)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '#remove' do
|
23
|
+
before (:each) {
|
24
|
+
repo.add(rule_01)
|
25
|
+
repo.add(rule_03)
|
26
|
+
repo.add(rule_02)
|
27
|
+
}
|
28
|
+
|
29
|
+
it "removes a rule" do
|
30
|
+
repo.remove(rule_02)
|
31
|
+
expect(repo.rules.last).to eql(rule_03)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe IceT::Schedule do
|
4
|
+
let!(:start_time) { Time.now }
|
5
|
+
let!(:end_time) { Time.now + 2.months }
|
6
|
+
let!(:schedule) { IceT::Schedule.new(start_time: start_time, end_time: end_time) }
|
7
|
+
let!(:daily_rule) { IceT::Rule::Daily.new(1) }
|
8
|
+
let!(:monthly_rule) { IceT::Rule::Monthly.new(1) }
|
9
|
+
let(:repo) { schedule.instance_variable_get(:@rules) }
|
10
|
+
|
11
|
+
describe '#add_rule' do
|
12
|
+
it "delegates to repository.add" do
|
13
|
+
expect(repo).to receive(:add).with(daily_rule)
|
14
|
+
schedule.add_rule(daily_rule)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe '#remove_rule' do
|
19
|
+
it "delegates to repository.remove" do
|
20
|
+
expect(repo).to receive(:remove).with(daily_rule)
|
21
|
+
schedule.remove_rule(daily_rule)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe '#rules' do
|
26
|
+
it "delegates to repository.rules" do
|
27
|
+
expect(repo).to receive(:rules)
|
28
|
+
schedule.rules
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe '#to_json' do
|
33
|
+
pending
|
34
|
+
end
|
35
|
+
|
36
|
+
describe '#to_yaml' do
|
37
|
+
pending
|
38
|
+
end
|
39
|
+
|
40
|
+
describe '::from_json' do
|
41
|
+
context "the created object" do
|
42
|
+
before do
|
43
|
+
schedule.add_rule(daily_rule)
|
44
|
+
schedule.add_rule(monthly_rule)
|
45
|
+
schedule.add_rule(IceT::Rule::Daily.new(12, "4pm"))
|
46
|
+
end
|
47
|
+
let(:json) { schedule.to_json }
|
48
|
+
let(:object) { IceT::Schedule.from_json(json) }
|
49
|
+
|
50
|
+
it "is a Schedule" do
|
51
|
+
expect(object).to be_an(IceT::Schedule)
|
52
|
+
end
|
53
|
+
it "contains the same rules as before" do
|
54
|
+
expect(object.rules.map(&:to_json)).to eql(schedule.rules.map(&:to_json))
|
55
|
+
end
|
56
|
+
|
57
|
+
[:start_time, :end_time].each { |time|
|
58
|
+
it "does have the same #{time} as before" do
|
59
|
+
expect(object.send(time).to_i).to eql(eval("#{time}").to_i)
|
60
|
+
end
|
61
|
+
}
|
62
|
+
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe '::from_yaml' do
|
67
|
+
pending
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler/setup'
|
3
|
+
# require 'active_support/all'
|
4
|
+
|
5
|
+
require 'ice_t'
|
6
|
+
|
7
|
+
Dir.glob(File.expand_path("spec/support/**/*.rb")).each{ |f| require f }
|
8
|
+
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
config.color_enabled = true
|
12
|
+
|
13
|
+
config.tty = true
|
14
|
+
|
15
|
+
config.formatter = :documentation # :progress, :html, :textmate
|
16
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
shared_examples 'a rule' do
|
2
|
+
|
3
|
+
describe '::to_i' do
|
4
|
+
it { expect(klass).to respond_to(:to_i) }
|
5
|
+
end
|
6
|
+
describe '::unit' do
|
7
|
+
it { expect(klass).to respond_to(:unit) }
|
8
|
+
end
|
9
|
+
|
10
|
+
describe '#occurrences' do
|
11
|
+
it { expect(klass.new).to respond_to(:occurrences) }
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '::from_json' do
|
15
|
+
pending
|
16
|
+
#it { expect(klass).to respond_to(:from_json) }
|
17
|
+
end
|
18
|
+
|
19
|
+
describe '::from_yaml' do
|
20
|
+
pending
|
21
|
+
#it { expect(klass).to respond_to(:from_yaml) }
|
22
|
+
end
|
23
|
+
|
24
|
+
describe '#to_json' do
|
25
|
+
it { expect(klass.new).to respond_to(:to_json) }
|
26
|
+
end
|
27
|
+
|
28
|
+
describe '#to_yaml' do
|
29
|
+
it { expect(klass.new).to respond_to(:to_yaml) }
|
30
|
+
end
|
31
|
+
|
32
|
+
describe '#@at' do
|
33
|
+
it {expect(klass.new(1, "4pm").at).to eql("4pm")}
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
describe 'comparison' do
|
38
|
+
classes = IceT::Rule::Base.descendants.sort
|
39
|
+
classes.each_with_index { | obj, i |
|
40
|
+
classes.each_with_index { | other, j |
|
41
|
+
case
|
42
|
+
when i == j
|
43
|
+
context 'on class level' do
|
44
|
+
it "#{obj} == #{other}" do
|
45
|
+
expect(obj==other).to be_true
|
46
|
+
end
|
47
|
+
end
|
48
|
+
context 'on instance level' do
|
49
|
+
it "#{obj}.new(1) == #{other}.new(1)" do
|
50
|
+
expect(obj.new(1) == other.new(1)).to be_true
|
51
|
+
end
|
52
|
+
it "#{obj}.new(1) < #{other}.new(2)" do
|
53
|
+
expect(obj.new(1) < other.new(2)).to be_true
|
54
|
+
end
|
55
|
+
it "#{obj}.new(2) > #{other}.new(1)" do
|
56
|
+
expect(obj.new(2) > other.new(1)).to be_true
|
57
|
+
end
|
58
|
+
it "#{obj}.new(1) <= #{other}.new(1)" do
|
59
|
+
expect(obj.new(1) <= other.new(1)).to be_true
|
60
|
+
end
|
61
|
+
it "#{obj}.new(1) >= #{other}.new(1)" do
|
62
|
+
expect(obj.new(1) >= other.new(1)).to be_true
|
63
|
+
end
|
64
|
+
end
|
65
|
+
when i > j
|
66
|
+
context 'on class level' do
|
67
|
+
it "#{obj} > #{other}" do
|
68
|
+
expect(obj > other).to be_true
|
69
|
+
end
|
70
|
+
end
|
71
|
+
context 'on instance level' do
|
72
|
+
it "#{obj}.new(1) > #{other}.new(1)" do
|
73
|
+
expect(obj.new(1) > other.new(1)).to be_true
|
74
|
+
end
|
75
|
+
end
|
76
|
+
when i < j
|
77
|
+
context 'on class level' do
|
78
|
+
it "#{obj} < #{other}" do
|
79
|
+
expect(obj < other).to be_true
|
80
|
+
end
|
81
|
+
end
|
82
|
+
context 'on instance level' do
|
83
|
+
it "#{obj}.new(1) < #{other}.new(1)" do
|
84
|
+
expect(obj.new(1) < other.new(1)).to be_true
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
}
|
89
|
+
}
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
metadata
ADDED
@@ -0,0 +1,189 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ice_t
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Christian Nennemann
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-12-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 4.0.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 4.0.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.3'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.13'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '2.13'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: turnip
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: guard
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: guard-rspec
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description: IceT is a ruby library for handling repeated events
|
112
|
+
email:
|
113
|
+
- christian.nennemann@gmail.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- .gitignore
|
119
|
+
- .travis.yml
|
120
|
+
- CHANGELOG.md
|
121
|
+
- Gemfile
|
122
|
+
- Guardfile
|
123
|
+
- LICENSE
|
124
|
+
- LICENSE.txt
|
125
|
+
- README.md
|
126
|
+
- Rakefile
|
127
|
+
- ice_t.gemspec
|
128
|
+
- lib/ice_t.rb
|
129
|
+
- lib/ice_t/conversions.rb
|
130
|
+
- lib/ice_t/exceptions.rb
|
131
|
+
- lib/ice_t/rule.rb
|
132
|
+
- lib/ice_t/rule/base.rb
|
133
|
+
- lib/ice_t/rule/daily.rb
|
134
|
+
- lib/ice_t/rule/hourly.rb
|
135
|
+
- lib/ice_t/rule/minutely.rb
|
136
|
+
- lib/ice_t/rule/monthly.rb
|
137
|
+
- lib/ice_t/rule/repository.rb
|
138
|
+
- lib/ice_t/rule/yearly.rb
|
139
|
+
- lib/ice_t/schedule.rb
|
140
|
+
- lib/ice_t/time_helper.rb
|
141
|
+
- lib/ice_t/version.rb
|
142
|
+
- lib/locales/en.yml
|
143
|
+
- spec/exceptions_spec.rb
|
144
|
+
- spec/rules/base_spec.rb
|
145
|
+
- spec/rules/daily_rule_spec.rb
|
146
|
+
- spec/rules/hourly_rule_spec.rb
|
147
|
+
- spec/rules/minutely_rule_spec.rb
|
148
|
+
- spec/rules/monthly_rule_spec.rb
|
149
|
+
- spec/rules/rules_repository_spec.rb
|
150
|
+
- spec/rules/yearly_rule_spec.rb
|
151
|
+
- spec/schedule_spec.rb
|
152
|
+
- spec/spec_helper.rb
|
153
|
+
- spec/support/shared_examples/rule_example.rb
|
154
|
+
homepage: https://github.com/XORwell/IceT
|
155
|
+
licenses:
|
156
|
+
- MIT
|
157
|
+
metadata: {}
|
158
|
+
post_install_message:
|
159
|
+
rdoc_options: []
|
160
|
+
require_paths:
|
161
|
+
- lib
|
162
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - '>='
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
167
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
168
|
+
requirements:
|
169
|
+
- - '>='
|
170
|
+
- !ruby/object:Gem::Version
|
171
|
+
version: '0'
|
172
|
+
requirements: []
|
173
|
+
rubyforge_project:
|
174
|
+
rubygems_version: 2.1.11
|
175
|
+
signing_key:
|
176
|
+
specification_version: 4
|
177
|
+
summary: Ruby Time Recurrence
|
178
|
+
test_files:
|
179
|
+
- spec/exceptions_spec.rb
|
180
|
+
- spec/rules/base_spec.rb
|
181
|
+
- spec/rules/daily_rule_spec.rb
|
182
|
+
- spec/rules/hourly_rule_spec.rb
|
183
|
+
- spec/rules/minutely_rule_spec.rb
|
184
|
+
- spec/rules/monthly_rule_spec.rb
|
185
|
+
- spec/rules/rules_repository_spec.rb
|
186
|
+
- spec/rules/yearly_rule_spec.rb
|
187
|
+
- spec/schedule_spec.rb
|
188
|
+
- spec/spec_helper.rb
|
189
|
+
- spec/support/shared_examples/rule_example.rb
|