ice_cube_ex 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.rspec +3 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +6 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +37 -0
- data/Rakefile +1 -0
- data/ice_cube_ex.gemspec +30 -0
- data/lib/ice_cube_ex.rb +10 -0
- data/lib/ice_cube_ex/ice_cube/rule.rb +12 -0
- data/lib/ice_cube_ex/ice_cube/rules/daily_cycle_rule.rb +68 -0
- data/lib/ice_cube_ex/ice_cube/validations/daily_cycle_interval.rb +76 -0
- data/lib/ice_cube_ex/version.rb +3 -0
- data/spec/ice_cube_ex/ice_cube/rule_spec.rb +16 -0
- data/spec/ice_cube_ex/ice_cube/rules/daily_cycle_spec.rb +27 -0
- data/spec/ice_cube_ex/ice_cube/schedule_spec.rb +123 -0
- data/spec/spec_helper.rb +13 -0
- metadata +154 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 3a1f31275d0e2a370214241ff1a1e6431fb40c2f
|
|
4
|
+
data.tar.gz: 7332e9354da6df596ec727898b5f61e65b1491f3
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 2c25a1c70946711f7fc347c4ce12b5215298d3b39bf008037c6227e9c694f62056128c9ca7ed1966c8ac84ae9963fec1bd4917fe7c7465cd2101a9ad8dfc0314
|
|
7
|
+
data.tar.gz: 18f44f2f3c74d3c33ddfcedb5aa4447bb63072db0ce4c9f9fd728094ec2a460c5f22b92eb74f1b343a86cd348f8e12e55ab204c4da9510b1b965d817c6d704d1
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.ruby-gemset
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
ice_cube_ex
|
data/.ruby-version
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
ruby-2.1.1
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2014 junhanamaki
|
|
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
|
+
# IceCubeEx
|
|
2
|
+
|
|
3
|
+
[](https://travis-ci.org/junhanamaki/ice_cube_ex)
|
|
4
|
+
[](https://codeclimate.com/github/junhanamaki/ice_cube_ex)
|
|
5
|
+
[](https://codeclimate.com/github/junhanamaki/ice_cube_ex)
|
|
6
|
+
[](https://gemnasium.com/junhanamaki/ice_cube_ex)
|
|
7
|
+
|
|
8
|
+
Extends gem [ice_cube](https://github.com/seejohnrun/ice_cube) to handle
|
|
9
|
+
custom rules, outside of the iCalendar spec.
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
First require ice_cube, and then require ice_cube_ex, by adding the following
|
|
14
|
+
line to your application's Gemfile:
|
|
15
|
+
|
|
16
|
+
gem 'ice_cube'
|
|
17
|
+
gem 'ice_cube_ex'
|
|
18
|
+
|
|
19
|
+
And then execute:
|
|
20
|
+
|
|
21
|
+
$ bundle
|
|
22
|
+
|
|
23
|
+
Or install it yourself as:
|
|
24
|
+
|
|
25
|
+
$ gem install ice_cube_ex
|
|
26
|
+
|
|
27
|
+
## Usage
|
|
28
|
+
|
|
29
|
+
TODO: Write usage instructions here
|
|
30
|
+
|
|
31
|
+
## Contributing
|
|
32
|
+
|
|
33
|
+
1. Fork it ( https://github.com/junhanamaki/ice_cube_ex/fork )
|
|
34
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
35
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
|
36
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
|
37
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require "bundler/gem_tasks"
|
data/ice_cube_ex.gemspec
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require 'ice_cube_ex/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "ice_cube_ex"
|
|
8
|
+
spec.version = IceCubeEx::VERSION
|
|
9
|
+
spec.authors = ["junhanamaki"]
|
|
10
|
+
spec.email = ["jun.hanamaki@gmail.com"]
|
|
11
|
+
spec.summary = %q{extending ice_cube with new rules}
|
|
12
|
+
spec.description = %q{extends ice_cube to handle more rules, check
|
|
13
|
+
homepage for more details}
|
|
14
|
+
spec.homepage = "https://github.com/junhanamaki/ice_cube_ex"
|
|
15
|
+
spec.license = "MIT"
|
|
16
|
+
|
|
17
|
+
spec.files = `git ls-files -z`.split("\x0")
|
|
18
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
|
19
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
|
20
|
+
spec.require_paths = ["lib"]
|
|
21
|
+
|
|
22
|
+
spec.required_ruby_version = '>= 1.9.3'
|
|
23
|
+
|
|
24
|
+
spec.add_development_dependency 'bundler', '~> 1.6'
|
|
25
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
|
26
|
+
spec.add_development_dependency 'simplecov', '~> 0.9'
|
|
27
|
+
spec.add_development_dependency 'codeclimate-test-reporter', '~> 0.3'
|
|
28
|
+
spec.add_development_dependency 'jazz_hands', '~> 0.5'
|
|
29
|
+
spec.add_development_dependency 'ice_cube', '~> 0.12'
|
|
30
|
+
end
|
data/lib/ice_cube_ex.rb
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
require 'ice_cube_ex/ice_cube/validations/daily_cycle_interval'
|
|
2
|
+
|
|
3
|
+
module IceCube
|
|
4
|
+
class DailyCycleRule < ValidatedRule
|
|
5
|
+
include Validations::DailyCycleInterval
|
|
6
|
+
|
|
7
|
+
def initialize(cycle, repeat)
|
|
8
|
+
super
|
|
9
|
+
cycle(cycle, repeat)
|
|
10
|
+
schedule_lock(:hour, :min, :sec)
|
|
11
|
+
reset
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
#
|
|
15
|
+
# cycle_start_time and why we start from one day before:
|
|
16
|
+
#
|
|
17
|
+
# given the following case:
|
|
18
|
+
#
|
|
19
|
+
# Schedule start_time 2014-2-2, DailyCycleRule with cycle 4, repeat 2
|
|
20
|
+
#
|
|
21
|
+
# if we invoke schedule.next_occurrence(2014-2-1), first calculated
|
|
22
|
+
# time will be 2014-2-2, which will give a day_count of 0, thus being lower
|
|
23
|
+
# than cycle_percentage and being a valid value.
|
|
24
|
+
# this by itself is not a problem, but it will ruin our cycle logic since
|
|
25
|
+
# only for the first case it will repeat 3 times instead of 2, because
|
|
26
|
+
# the following dates will be valid:
|
|
27
|
+
#
|
|
28
|
+
# 2014-2-2, 2014-2-3, 2014-2-4
|
|
29
|
+
#
|
|
30
|
+
# so to avoid this we start counting from start_time - 1.day
|
|
31
|
+
def next_time(time, schedule, closing_time)
|
|
32
|
+
@time = time
|
|
33
|
+
@schedule = schedule
|
|
34
|
+
cycle_start_time = schedule.start_time - 24 * 60 * 60
|
|
35
|
+
|
|
36
|
+
return nil unless find_acceptable_time_before(closing_time)
|
|
37
|
+
day_count = number_of_days_between(@time, cycle_start_time)
|
|
38
|
+
acceptable_time_percentage = calculate_cycle_percentage(day_count)
|
|
39
|
+
|
|
40
|
+
until acceptable_time_percentage <= @cycle_percentage
|
|
41
|
+
@time += 1
|
|
42
|
+
return nil unless find_acceptable_time_before(closing_time)
|
|
43
|
+
day_count = number_of_days_between(@time, cycle_start_time)
|
|
44
|
+
acceptable_time_percentage = calculate_cycle_percentage(day_count)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
@uses += 1 if @time
|
|
48
|
+
@time
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def number_of_days_between(acceptable_time, initial_time)
|
|
52
|
+
acceptable_time_date = get_date(acceptable_time)
|
|
53
|
+
initial_time_date = get_date(initial_time)
|
|
54
|
+
|
|
55
|
+
((acceptable_time_date - initial_time_date) / (24 * 60 * 60)).to_i
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def get_date(time)
|
|
59
|
+
Time.new(time.year, time.month, time.day, 0, 0, 0, '+00:00')
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def calculate_cycle_percentage(day_count)
|
|
63
|
+
value = (day_count.to_f / @cycle.to_f)
|
|
64
|
+
percentage = ((value - value.to_i) * 100).to_i
|
|
65
|
+
percentage.zero? ? 100 : percentage
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
module IceCube
|
|
2
|
+
module Validations
|
|
3
|
+
module DailyCycleInterval
|
|
4
|
+
attr_accessor :rule
|
|
5
|
+
|
|
6
|
+
def cycle(cycle, repeat)
|
|
7
|
+
@interval = 1
|
|
8
|
+
@repeat = normalize(repeat)
|
|
9
|
+
@cycle = normalize(cycle)
|
|
10
|
+
|
|
11
|
+
unless @repeat < @cycle
|
|
12
|
+
raise ArgumentError, 'cycle has to be a value higher than repeat'
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
@cycle_percentage = ((@repeat.to_f / @cycle.to_f) * 100).to_i
|
|
16
|
+
replace_validations_for \
|
|
17
|
+
:interval, [Validation.new(@interval, @cycle, @repeat)]
|
|
18
|
+
clobber_base_validations(:wday, :day)
|
|
19
|
+
self
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
class Validation
|
|
23
|
+
attr_reader :interval, :cycle, :repeat
|
|
24
|
+
|
|
25
|
+
def initialize(interval, cycle, repeat)
|
|
26
|
+
@interval = interval
|
|
27
|
+
@cycle = cycle
|
|
28
|
+
@repeat = repeat
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def type
|
|
32
|
+
:day
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def dst_adjust?
|
|
36
|
+
true
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def validate(step_time, schedule)
|
|
40
|
+
t0, t1 = schedule.start_time, step_time
|
|
41
|
+
days = Date.new(t1.year, t1.month, t1.day) -
|
|
42
|
+
Date.new(t0.year, t0.month, t0.day)
|
|
43
|
+
offset = (days % interval).nonzero?
|
|
44
|
+
interval - offset if offset
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def build_s(builder)
|
|
48
|
+
builder.base = "Every #{cycle} days, repeat #{repeat} times"
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def build_hash(builder)
|
|
52
|
+
builder[:interval] = interval
|
|
53
|
+
builder[:cycle] = cycle
|
|
54
|
+
builder[:repeat] = repeat
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def build_ical(builder)
|
|
58
|
+
builder['FREQ'] << 'DAILY_CYCLE (CUSTOM RULE)'
|
|
59
|
+
builder['CYCLE'] << cycle
|
|
60
|
+
builder['REPEAT'] << repeat
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
private
|
|
65
|
+
|
|
66
|
+
def normalize(arg)
|
|
67
|
+
arg.to_i.tap do |val|
|
|
68
|
+
unless val > 1
|
|
69
|
+
raise ArgumentError, "'#{arg}' is not a valid argument. " \
|
|
70
|
+
"Please pass an integer higher than 1."
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe IceCube::Rule do
|
|
4
|
+
describe '.daily_cycle' do
|
|
5
|
+
context 'every 5 days, ' \
|
|
6
|
+
'repeat 3 days' do
|
|
7
|
+
let(:cycle) { 5 }
|
|
8
|
+
let(:repeat) { 3 }
|
|
9
|
+
before { @rule = IceCube::Rule.daily_cycle(cycle, repeat) }
|
|
10
|
+
|
|
11
|
+
it 'returns an instance of DailyCycleRule' do
|
|
12
|
+
expect(@rule.class).to eq(IceCube::DailyCycleRule)
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe IceCube::DailyCycleRule do
|
|
4
|
+
describe '.new' do
|
|
5
|
+
context 'given cycle argument bellow 2' do
|
|
6
|
+
let(:cycle) { 0 }
|
|
7
|
+
let(:repeat) { 1 }
|
|
8
|
+
|
|
9
|
+
it 'raises error' do
|
|
10
|
+
expect do
|
|
11
|
+
IceCube::DailyCycleRule.new(cycle, repeat)
|
|
12
|
+
end.to raise_error
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
context 'given cycle argument lower than repeat' do
|
|
17
|
+
let(:cycle) { 9 }
|
|
18
|
+
let(:repeat) { 10 }
|
|
19
|
+
|
|
20
|
+
it 'raises error' do
|
|
21
|
+
expect do
|
|
22
|
+
IceCube::DailyCycleRule.new(cycle, repeat)
|
|
23
|
+
end.to raise_error
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe IceCube::Schedule do
|
|
4
|
+
describe '.next_occurrence' do
|
|
5
|
+
context 'given schedule starting at 4-2-2012 at 12 hours' do
|
|
6
|
+
let(:start_time) do
|
|
7
|
+
Time.new(2012, 2, 4, 12)
|
|
8
|
+
end
|
|
9
|
+
let(:schedule) do
|
|
10
|
+
IceCube::Schedule.new(start_time) do |c|
|
|
11
|
+
c.rrule rule
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
context 'given rule of type DailyCycleRule initialized to ' \
|
|
16
|
+
'every 4 days (cycle), ' \
|
|
17
|
+
'repeat 2 days (repeat)' do
|
|
18
|
+
let(:repeat) { 2 }
|
|
19
|
+
let(:cycle) { 4 }
|
|
20
|
+
let(:rule) { IceCube::DailyCycleRule.new(cycle, repeat) }
|
|
21
|
+
|
|
22
|
+
context 'calculating from 3-2-2012' do
|
|
23
|
+
let(:from) { Time.new(2012, 2, 3) }
|
|
24
|
+
let(:first_occurrence) { schedule.next_occurrence from }
|
|
25
|
+
let(:second_occurrence) { schedule.next_occurrence first_occurrence }
|
|
26
|
+
let(:third_occurrence) { schedule.next_occurrence second_occurrence }
|
|
27
|
+
let(:fourth_occurrence) { schedule.next_occurrence third_occurrence }
|
|
28
|
+
let(:fifth_occurrence) { schedule.next_occurrence fourth_occurrence }
|
|
29
|
+
let(:sixth_occurrence) { schedule.next_occurrence fifth_occurrence }
|
|
30
|
+
|
|
31
|
+
it 'returns 4-2-2012 at 12am as first occurrence' do
|
|
32
|
+
expect(first_occurrence).to eq(start_time)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
it 'returns 5-2-2012 at 12am as second occurrence' do
|
|
36
|
+
expect(second_occurrence).to eq(Time.new(2012, 2, 5, 12))
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
it 'returns 8-2-2012 at 12am as third occurrence', test: true do
|
|
40
|
+
expect(third_occurrence).to eq(Time.new(2012, 2, 8, 12))
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
it 'returns 9-2-2012 at 12am as fourth occurrence' do
|
|
44
|
+
expect(fourth_occurrence).to eq(Time.new(2012, 2, 9, 12))
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
it 'returns 12-2-2012 at 12am as fifth occurrence', test: true do
|
|
48
|
+
expect(fifth_occurrence).to eq(Time.new(2012, 2, 12, 12))
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
it 'returns 13-2-2012 at 12am as sixth occurrence' do
|
|
52
|
+
expect(sixth_occurrence).to eq(Time.new(2012, 2, 13, 12))
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
context 'given rule of type DailyCycleRule initialized to ' \
|
|
58
|
+
'every 4 days (cycle), ' \
|
|
59
|
+
'repeat 2 days (repeat), ' \
|
|
60
|
+
'which repeats 3 times (count)' do
|
|
61
|
+
let(:repeat) { 2 }
|
|
62
|
+
let(:cycle) { 4 }
|
|
63
|
+
let(:count) { 3 }
|
|
64
|
+
let(:rule) { IceCube::DailyCycleRule.new(cycle, repeat).count(3) }
|
|
65
|
+
|
|
66
|
+
context 'calculating from 3-2-2012' do
|
|
67
|
+
let(:from) { Time.new(2012, 2, 3) }
|
|
68
|
+
let(:first_occurrence) { schedule.next_occurrence from }
|
|
69
|
+
let(:second_occurrence) { schedule.next_occurrence first_occurrence }
|
|
70
|
+
let(:third_occurrence) { schedule.next_occurrence second_occurrence }
|
|
71
|
+
let(:fourth_occurrence) { schedule.next_occurrence third_occurrence }
|
|
72
|
+
|
|
73
|
+
it 'returns 4-2-2012 at 12am as first occurrence' do
|
|
74
|
+
expect(first_occurrence).to eq(start_time)
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
it 'returns 5-2-2012 at 12am as second occurrence' do
|
|
78
|
+
expect(second_occurrence).to eq(Time.new(2012, 2, 5, 12))
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
it 'returns 8-2-2012 at 12am as third occurrence', test: true do
|
|
82
|
+
expect(third_occurrence).to eq(Time.new(2012, 2, 8, 12))
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
it 'returns nil as fourth occurrence' do
|
|
86
|
+
expect(fourth_occurrence).to eq(nil)
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
context 'given rule of type DailyCycleRule initialized to ' \
|
|
92
|
+
'every 4 days (cycle), ' \
|
|
93
|
+
'repeat 2 days (repeat), ' \
|
|
94
|
+
'which repeats until 6-2-2012' do
|
|
95
|
+
let(:repeat) { 2 }
|
|
96
|
+
let(:cycle) { 4 }
|
|
97
|
+
let(:repeat_until) { Time.new(2012, 2, 6) }
|
|
98
|
+
let(:rule) do
|
|
99
|
+
IceCube::DailyCycleRule.new(cycle, repeat).until(repeat_until)
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
context 'calculating from 3-2-2012' do
|
|
103
|
+
let(:from) { Time.new(2012, 2, 3) }
|
|
104
|
+
let(:first_occurrence) { schedule.next_occurrence from }
|
|
105
|
+
let(:second_occurrence) { schedule.next_occurrence first_occurrence }
|
|
106
|
+
let(:third_occurrence) { schedule.next_occurrence second_occurrence }
|
|
107
|
+
|
|
108
|
+
it 'returns 4-2-2012 at 12am as first occurrence' do
|
|
109
|
+
expect(first_occurrence).to eq(start_time)
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
it 'returns 5-2-2012 at 12am as second occurrence' do
|
|
113
|
+
expect(second_occurrence).to eq(Time.new(2012, 2, 5, 12))
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
it 'returns nil as third occurrence', test: true do
|
|
117
|
+
expect(third_occurrence).to eq(nil)
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
end
|
|
123
|
+
end
|
data/spec/spec_helper.rb
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
if ENV['CODECLIMATE_REPO_TOKEN'].nil?
|
|
2
|
+
require 'simplecov'
|
|
3
|
+
SimpleCov.start do
|
|
4
|
+
coverage_dir 'tmp/coverage'
|
|
5
|
+
end
|
|
6
|
+
else
|
|
7
|
+
require "codeclimate-test-reporter"
|
|
8
|
+
CodeClimate::TestReporter.start
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
require 'pry'
|
|
12
|
+
require 'ice_cube'
|
|
13
|
+
require 'ice_cube_ex'
|
metadata
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: ice_cube_ex
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- junhanamaki
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2014-07-27 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: bundler
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '1.6'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '1.6'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: rspec
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '3.0'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '3.0'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: simplecov
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '0.9'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '0.9'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: codeclimate-test-reporter
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - "~>"
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '0.3'
|
|
62
|
+
type: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - "~>"
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '0.3'
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: jazz_hands
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - "~>"
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '0.5'
|
|
76
|
+
type: :development
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - "~>"
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: '0.5'
|
|
83
|
+
- !ruby/object:Gem::Dependency
|
|
84
|
+
name: ice_cube
|
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
|
86
|
+
requirements:
|
|
87
|
+
- - "~>"
|
|
88
|
+
- !ruby/object:Gem::Version
|
|
89
|
+
version: '0.12'
|
|
90
|
+
type: :development
|
|
91
|
+
prerelease: false
|
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
93
|
+
requirements:
|
|
94
|
+
- - "~>"
|
|
95
|
+
- !ruby/object:Gem::Version
|
|
96
|
+
version: '0.12'
|
|
97
|
+
description: |-
|
|
98
|
+
extends ice_cube to handle more rules, check
|
|
99
|
+
homepage for more details
|
|
100
|
+
email:
|
|
101
|
+
- jun.hanamaki@gmail.com
|
|
102
|
+
executables: []
|
|
103
|
+
extensions: []
|
|
104
|
+
extra_rdoc_files: []
|
|
105
|
+
files:
|
|
106
|
+
- ".gitignore"
|
|
107
|
+
- ".rspec"
|
|
108
|
+
- ".ruby-gemset"
|
|
109
|
+
- ".ruby-version"
|
|
110
|
+
- ".travis.yml"
|
|
111
|
+
- Gemfile
|
|
112
|
+
- LICENSE.txt
|
|
113
|
+
- README.md
|
|
114
|
+
- Rakefile
|
|
115
|
+
- ice_cube_ex.gemspec
|
|
116
|
+
- lib/ice_cube_ex.rb
|
|
117
|
+
- lib/ice_cube_ex/ice_cube/rule.rb
|
|
118
|
+
- lib/ice_cube_ex/ice_cube/rules/daily_cycle_rule.rb
|
|
119
|
+
- lib/ice_cube_ex/ice_cube/validations/daily_cycle_interval.rb
|
|
120
|
+
- lib/ice_cube_ex/version.rb
|
|
121
|
+
- spec/ice_cube_ex/ice_cube/rule_spec.rb
|
|
122
|
+
- spec/ice_cube_ex/ice_cube/rules/daily_cycle_spec.rb
|
|
123
|
+
- spec/ice_cube_ex/ice_cube/schedule_spec.rb
|
|
124
|
+
- spec/spec_helper.rb
|
|
125
|
+
homepage: https://github.com/junhanamaki/ice_cube_ex
|
|
126
|
+
licenses:
|
|
127
|
+
- MIT
|
|
128
|
+
metadata: {}
|
|
129
|
+
post_install_message:
|
|
130
|
+
rdoc_options: []
|
|
131
|
+
require_paths:
|
|
132
|
+
- lib
|
|
133
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
134
|
+
requirements:
|
|
135
|
+
- - ">="
|
|
136
|
+
- !ruby/object:Gem::Version
|
|
137
|
+
version: 1.9.3
|
|
138
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
139
|
+
requirements:
|
|
140
|
+
- - ">="
|
|
141
|
+
- !ruby/object:Gem::Version
|
|
142
|
+
version: '0'
|
|
143
|
+
requirements: []
|
|
144
|
+
rubyforge_project:
|
|
145
|
+
rubygems_version: 2.2.2
|
|
146
|
+
signing_key:
|
|
147
|
+
specification_version: 4
|
|
148
|
+
summary: extending ice_cube with new rules
|
|
149
|
+
test_files:
|
|
150
|
+
- spec/ice_cube_ex/ice_cube/rule_spec.rb
|
|
151
|
+
- spec/ice_cube_ex/ice_cube/rules/daily_cycle_spec.rb
|
|
152
|
+
- spec/ice_cube_ex/ice_cube/schedule_spec.rb
|
|
153
|
+
- spec/spec_helper.rb
|
|
154
|
+
has_rdoc:
|