timeloop 1.0.0
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 +15 -0
- data/.gitignore +22 -0
- data/.rspec +4 -0
- data/.travis.yml +7 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +22 -0
- data/README.md +92 -0
- data/Rakefile +6 -0
- data/lib/timeloop/core_ext/integer/time.rb +12 -0
- data/lib/timeloop/core_ext/integer.rb +1 -0
- data/lib/timeloop/core_ext/numeric/time.rb +33 -0
- data/lib/timeloop/core_ext/numeric.rb +1 -0
- data/lib/timeloop/core_ext.rb +2 -0
- data/lib/timeloop/every.rb +58 -0
- data/lib/timeloop/version.rb +3 -0
- data/lib/timeloop.rb +7 -0
- data/spec/spec_helper.rb +27 -0
- data/spec/unit/core_ext/integer_spec.rb +55 -0
- data/spec/unit/core_ext/numeric_spec.rb +231 -0
- data/timeloop.gemspec +23 -0
- metadata +108 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
N2EyYjI2NjY3NTY0OThmNTk3MDdmNzFjZTZmYWQxZWY4NTJkOWFmZA==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
ZjQwMWFhMWM4OGFiNzMxYzJiNGNiOTQ3YzNjODkzNDRmZGU3NGM1ZQ==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
N2QxYTgwNGE3M2Q5NjVjODY5OTNiYjdlNDliMjFhYTBmZjkyYWJkNWNmZjFl
|
10
|
+
ZGZlODA0YWUzMTJhZDIxOGUyN2U4YTkwZGYwOGJlM2FiYTAzM2EzZTRjMzA3
|
11
|
+
YWZmY2RjN2FlM2QzYWIwMGYyZDlkMWVkOWUwZjdmNWYzMTliNzM=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
NGQxYTA5N2M0MzI3ODRlZDY3YzAwYTViZjE2MGUxOGMxYTRlYTQzODY2ODE3
|
14
|
+
YjFlZDhjZjNhOTZkNjhjY2U2YjhhOTJmYjgyOTk1YzMxNjU5ODA3NDdlYjRl
|
15
|
+
Yjk3NDkyZGNlOTRlM2U0Nzc4YzBhODRjYTczOWJhNGNhZDI5Mzc=
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Maciej Paruszewski
|
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,92 @@
|
|
1
|
+
# Timeloop
|
2
|
+
|
3
|
+
Timeloop is a simple Ruby gem that provides loop with time interval inspired on 'every' method from whenever gem.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'timeloop'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install timeloop
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Require gem in you Ruby file:
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
require 'timeloop'
|
25
|
+
|
26
|
+
every 10.seconds do
|
27
|
+
puts '10 seconds delay'
|
28
|
+
end
|
29
|
+
|
30
|
+
# Result:
|
31
|
+
|
32
|
+
# 10 seconds delay
|
33
|
+
# 10 seconds delay
|
34
|
+
# 10 seconds delay
|
35
|
+
# ...
|
36
|
+
|
37
|
+
every 3.hours do
|
38
|
+
Mail.deliver do
|
39
|
+
from 'me@test.email'
|
40
|
+
to 'you@test.email'
|
41
|
+
subject '1 hour message'
|
42
|
+
body 'Hi, you will get that message every hour. Be prepared!'
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
every :minute do
|
47
|
+
product = 2 * 2
|
48
|
+
puts "and 2 * 2 is still #{product}"
|
49
|
+
end
|
50
|
+
|
51
|
+
# Result:
|
52
|
+
|
53
|
+
# and 2*2 is still 4
|
54
|
+
# and 2*2 is still 4
|
55
|
+
# and 2*2 is still 4
|
56
|
+
# ...
|
57
|
+
```
|
58
|
+
|
59
|
+
You can also specify how many times your block will be evaluated:
|
60
|
+
|
61
|
+
```ruby
|
62
|
+
every 10.seconds, maxium: 4.times do |i|
|
63
|
+
puts i
|
64
|
+
end
|
65
|
+
|
66
|
+
# Result:
|
67
|
+
|
68
|
+
# 0
|
69
|
+
# 1
|
70
|
+
# 2
|
71
|
+
# 3
|
72
|
+
# => 4
|
73
|
+
|
74
|
+
every 'second', maxium: 3 do |i|
|
75
|
+
puts 'You will see me only 3 times.'
|
76
|
+
end
|
77
|
+
|
78
|
+
# Result:
|
79
|
+
|
80
|
+
# You will see me only 3 times.
|
81
|
+
# You will see me only 3 times.
|
82
|
+
# You will see me only 3 times.
|
83
|
+
# => 3
|
84
|
+
```
|
85
|
+
|
86
|
+
## Contributing
|
87
|
+
|
88
|
+
1. Fork it ( https://github.com/pinoss/timeloop/fork )
|
89
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
90
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
91
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
92
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'timeloop/core_ext/integer/time'
|
@@ -0,0 +1,33 @@
|
|
1
|
+
class Numeric
|
2
|
+
|
3
|
+
def miliseconds
|
4
|
+
self/1000.0
|
5
|
+
end
|
6
|
+
alias :milisecond :miliseconds
|
7
|
+
|
8
|
+
def seconds
|
9
|
+
self
|
10
|
+
end
|
11
|
+
alias :second :seconds
|
12
|
+
|
13
|
+
def minutes
|
14
|
+
60 * self
|
15
|
+
end
|
16
|
+
alias :minute :minutes
|
17
|
+
|
18
|
+
def hours
|
19
|
+
60 * self.minutes
|
20
|
+
end
|
21
|
+
alias :hour :hours
|
22
|
+
|
23
|
+
def days
|
24
|
+
24 * self.hours
|
25
|
+
end
|
26
|
+
alias :day :days
|
27
|
+
|
28
|
+
def weeks
|
29
|
+
7 * self.days
|
30
|
+
end
|
31
|
+
alias :week :weeks
|
32
|
+
|
33
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'timeloop/core_ext/numeric/time'
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module Timeloop
|
2
|
+
module Every
|
3
|
+
|
4
|
+
def every(value, opts = {})
|
5
|
+
maximum = parse_maximum_value(opts.fetch(:maximum)) if opts.key? :maximum
|
6
|
+
frequency = parse_frequency(value)
|
7
|
+
|
8
|
+
if maximum.nil?
|
9
|
+
i = 0
|
10
|
+
loop do
|
11
|
+
yield(i) if block_given?
|
12
|
+
sleep frequency
|
13
|
+
|
14
|
+
i += 1
|
15
|
+
end
|
16
|
+
else
|
17
|
+
maximum.times do |i|
|
18
|
+
yield(i) if block_given?
|
19
|
+
sleep frequency
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def parse_frequency(frequency)
|
27
|
+
case frequency
|
28
|
+
when Numeric
|
29
|
+
frequency
|
30
|
+
when :second, 'second'
|
31
|
+
1.second
|
32
|
+
when :minute, 'second'
|
33
|
+
1.minute
|
34
|
+
when :hour, 'hour'
|
35
|
+
1.hour
|
36
|
+
when :day, 'day'
|
37
|
+
1.day
|
38
|
+
when :month, 'month'
|
39
|
+
1.month
|
40
|
+
when :year, 'year'
|
41
|
+
1.year
|
42
|
+
else
|
43
|
+
fail ArgumentError.new('wrong type of argument (should be a Numeric, Symbol or String)')
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def parse_maximum_value(maximum)
|
48
|
+
case maximum
|
49
|
+
when Enumerator
|
50
|
+
maximum.count
|
51
|
+
when Integer
|
52
|
+
maximum
|
53
|
+
else
|
54
|
+
fail ArgumentError.new('wrong type of argument (should be an Enumerator or Integer)')
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
data/lib/timeloop.rb
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
Bundler.setup
|
3
|
+
|
4
|
+
require 'timeloop'
|
5
|
+
|
6
|
+
RSpec.configure do |config|
|
7
|
+
config.filter_run :focus
|
8
|
+
config.run_all_when_everything_filtered = true
|
9
|
+
|
10
|
+
if config.files_to_run.one?
|
11
|
+
config.default_formatter = 'doc'
|
12
|
+
end
|
13
|
+
|
14
|
+
config.profile_examples = 10
|
15
|
+
config.order = :random
|
16
|
+
|
17
|
+
Kernel.srand config.seed
|
18
|
+
|
19
|
+
config.expect_with :rspec do |expectations|
|
20
|
+
expectations.syntax = :expect
|
21
|
+
end
|
22
|
+
|
23
|
+
config.mock_with :rspec do |mocks|
|
24
|
+
mocks.syntax = :expect
|
25
|
+
mocks.verify_partial_doubles = true
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Integer do
|
4
|
+
describe '#months' do
|
5
|
+
it 'returns 0.month as seconds' do
|
6
|
+
seconds = 0
|
7
|
+
expect(0.month).to eq(seconds)
|
8
|
+
expect(0.months).to eq(seconds)
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'returns 1 month as seconds' do
|
12
|
+
seconds = 1 * 30 * 24 * 60 * 60
|
13
|
+
expect(1.month).to eq(seconds)
|
14
|
+
expect(1.months).to eq(seconds)
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'returns 3 months as seconds' do
|
18
|
+
seconds = 3 * 30 * 24 * 60 * 60
|
19
|
+
expect(3.month).to eq(seconds)
|
20
|
+
expect(3.months).to eq(seconds)
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'returns -2 months as seconds' do
|
24
|
+
seconds = -2 * 30 * 24 * 60 * 60
|
25
|
+
expect(-2.month).to eq(seconds)
|
26
|
+
expect(-2.months).to eq(seconds)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe '#years' do
|
31
|
+
it 'returns 0 years as seconds' do
|
32
|
+
seconds = 0
|
33
|
+
expect(0.year).to eq(seconds)
|
34
|
+
expect(0.years).to eq(seconds)
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'returns 1 month as seconds' do
|
38
|
+
seconds = 1 * 365.25 * 24 * 60 * 60
|
39
|
+
expect(1.year).to eq(seconds)
|
40
|
+
expect(1.years).to eq(seconds)
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'returns 3 years as seconds' do
|
44
|
+
seconds = 3 * 365.25 * 24 * 60 * 60
|
45
|
+
expect(3.year).to eq(seconds)
|
46
|
+
expect(3.years).to eq(seconds)
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'returns -2 years as seconds' do
|
50
|
+
seconds = -2 * 365.25 * 24 * 60 * 60
|
51
|
+
expect(-2.year).to eq(seconds)
|
52
|
+
expect(-2.years).to eq(seconds)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,231 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Numeric do
|
4
|
+
describe '#miliseconds' do
|
5
|
+
it 'returns 0 milisecond as seconds' do
|
6
|
+
seconds = 0
|
7
|
+
expect(0.milisecond).to eq(seconds)
|
8
|
+
expect(0.miliseconds).to eq(seconds)
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'returns 1 milisecond as seconds' do
|
12
|
+
seconds = 1 / 1000.0
|
13
|
+
expect(1.milisecond).to eq(seconds)
|
14
|
+
expect(1.miliseconds).to eq(seconds)
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'returns 3 miliseconds as seconds' do
|
18
|
+
seconds = 3 / 1000.0
|
19
|
+
expect(3.milisecond).to eq(seconds)
|
20
|
+
expect(3.miliseconds).to eq(seconds)
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'returns 75.6 miliseconds as seconds' do
|
24
|
+
seconds = 75.6 / 1000.0
|
25
|
+
expect(75.6.milisecond).to eq(seconds)
|
26
|
+
expect(75.6.miliseconds).to eq(seconds)
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'returns -2 miliseconds as seconds' do
|
30
|
+
seconds = -2 / 1000.0
|
31
|
+
expect(-2.milisecond).to eq(seconds)
|
32
|
+
expect(-2.miliseconds).to eq(seconds)
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'returns -2.7 miliseconds as seconds' do
|
36
|
+
seconds = -2.7 / 1000.0
|
37
|
+
expect(-2.7.milisecond).to eq(seconds)
|
38
|
+
expect(-2.7.miliseconds).to eq(seconds)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe '#seconds' do
|
43
|
+
it 'returns 0 second as seconds' do
|
44
|
+
seconds = 0
|
45
|
+
expect(0.second).to eq(seconds)
|
46
|
+
expect(0.seconds).to eq(seconds)
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'returns 1 second as seconds' do
|
50
|
+
seconds = 1
|
51
|
+
expect(1.second).to eq(seconds)
|
52
|
+
expect(1.seconds).to eq(seconds)
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'returns 3 seconds as seconds' do
|
56
|
+
seconds = 3
|
57
|
+
expect(3.second).to eq(seconds)
|
58
|
+
expect(3.seconds).to eq(seconds)
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'returns 75.6 seconds as seconds' do
|
62
|
+
seconds = 75.6
|
63
|
+
expect(75.6.second).to eq(seconds)
|
64
|
+
expect(75.6.seconds).to eq(seconds)
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'returns -2 seconds as seconds' do
|
68
|
+
seconds = -2
|
69
|
+
expect(-2.second).to eq(seconds)
|
70
|
+
expect(-2.seconds).to eq(seconds)
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'returns -2.7 seconds as seconds' do
|
74
|
+
seconds = -2.7
|
75
|
+
expect(-2.7.second).to eq(seconds)
|
76
|
+
expect(-2.7.seconds).to eq(seconds)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
describe '#minutes' do
|
81
|
+
it 'returns 0 minute as seconds' do
|
82
|
+
seconds = 0 * 60
|
83
|
+
expect(0.minute).to eq(seconds)
|
84
|
+
expect(0.minutes).to eq(seconds)
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'returns 1 minute as seconds' do
|
88
|
+
seconds = 1 * 60
|
89
|
+
expect(1.minute).to eq(seconds)
|
90
|
+
expect(1.minutes).to eq(seconds)
|
91
|
+
end
|
92
|
+
|
93
|
+
it 'returns 3 seconds as seconds' do
|
94
|
+
seconds = 3 * 60
|
95
|
+
expect(3.minute).to eq(seconds)
|
96
|
+
expect(3.minutes).to eq(seconds)
|
97
|
+
end
|
98
|
+
|
99
|
+
it 'returns 75.6 minutes as seconds' do
|
100
|
+
seconds = 75.6 * 60
|
101
|
+
expect(75.6.minute).to eq(seconds)
|
102
|
+
expect(75.6.minutes).to eq(seconds)
|
103
|
+
end
|
104
|
+
|
105
|
+
it 'returns -2 minutes as seconds' do
|
106
|
+
seconds = -2 * 60
|
107
|
+
expect(-2.minute).to eq(seconds)
|
108
|
+
expect(-2.minutes).to eq(seconds)
|
109
|
+
end
|
110
|
+
|
111
|
+
it 'returns -2.7 minutes as seconds' do
|
112
|
+
seconds = -2.7 * 60
|
113
|
+
expect(-2.7.minute).to eq(seconds)
|
114
|
+
expect(-2.7.minutes).to eq(seconds)
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
describe '#hours' do
|
119
|
+
it 'returns 0 hour as seconds' do
|
120
|
+
seconds = 0 * 60 * 60
|
121
|
+
expect(0.hour).to eq(seconds)
|
122
|
+
expect(0.hours).to eq(seconds)
|
123
|
+
end
|
124
|
+
|
125
|
+
it 'returns 1 hour as seconds' do
|
126
|
+
seconds = 1 * 60 * 60
|
127
|
+
expect(1.hour).to eq(seconds)
|
128
|
+
expect(1.hours).to eq(seconds)
|
129
|
+
end
|
130
|
+
|
131
|
+
it 'returns 3 seconds as seconds' do
|
132
|
+
seconds = 3 * 60 * 60
|
133
|
+
expect(3.hour).to eq(seconds)
|
134
|
+
expect(3.hours).to eq(seconds)
|
135
|
+
end
|
136
|
+
|
137
|
+
it 'returns 75.6 hours as seconds' do
|
138
|
+
seconds = 75.6 * 60 * 60
|
139
|
+
expect(75.6.hour).to eq(seconds)
|
140
|
+
expect(75.6.hours).to eq(seconds)
|
141
|
+
end
|
142
|
+
|
143
|
+
it 'returns -2 hours as seconds' do
|
144
|
+
seconds = -2 * 60 * 60
|
145
|
+
expect(-2.hour).to eq(seconds)
|
146
|
+
expect(-2.hours).to eq(seconds)
|
147
|
+
end
|
148
|
+
|
149
|
+
it 'returns -2.7 hours as seconds' do
|
150
|
+
seconds = -2.7 * 60 * 60
|
151
|
+
expect(-2.7.hour).to eq(seconds)
|
152
|
+
expect(-2.7.hours).to eq(seconds)
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
describe '#days' do
|
157
|
+
it 'returns 0 day as seconds' do
|
158
|
+
seconds = 0 * 60 * 60 * 24
|
159
|
+
expect(0.day).to eq(seconds)
|
160
|
+
expect(0.days).to eq(seconds)
|
161
|
+
end
|
162
|
+
|
163
|
+
it 'returns 1 day as seconds' do
|
164
|
+
seconds = 1 * 60 * 60 * 24
|
165
|
+
expect(1.day).to eq(seconds)
|
166
|
+
expect(1.days).to eq(seconds)
|
167
|
+
end
|
168
|
+
|
169
|
+
it 'returns 3 seconds as seconds' do
|
170
|
+
seconds = 3 * 60 * 60 * 24
|
171
|
+
expect(3.day).to eq(seconds)
|
172
|
+
expect(3.days).to eq(seconds)
|
173
|
+
end
|
174
|
+
|
175
|
+
it 'returns 75.6 days as seconds' do
|
176
|
+
seconds = 75.6 * 60 * 60 * 24
|
177
|
+
expect(75.6.day).to eq(seconds)
|
178
|
+
expect(75.6.days).to eq(seconds)
|
179
|
+
end
|
180
|
+
|
181
|
+
it 'returns -2 days as seconds' do
|
182
|
+
seconds = -2 * 60 * 60 * 24
|
183
|
+
expect(-2.day).to eq(seconds)
|
184
|
+
expect(-2.days).to eq(seconds)
|
185
|
+
end
|
186
|
+
|
187
|
+
it 'returns -2.7 days as seconds' do
|
188
|
+
seconds = -2.7 * 60 * 60 * 24
|
189
|
+
expect(-2.7.day).to eq(seconds)
|
190
|
+
expect(-2.7.days).to eq(seconds)
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
describe '#weeks' do
|
195
|
+
it 'returns 0 week as seconds' do
|
196
|
+
seconds = 0 * 60 * 60 * 24 * 7
|
197
|
+
expect(0.week).to eq(seconds)
|
198
|
+
expect(0.weeks).to eq(seconds)
|
199
|
+
end
|
200
|
+
|
201
|
+
it 'returns 1 week as seconds' do
|
202
|
+
seconds = 1 * 60 * 60 * 24 * 7
|
203
|
+
expect(1.week).to eq(seconds)
|
204
|
+
expect(1.weeks).to eq(seconds)
|
205
|
+
end
|
206
|
+
|
207
|
+
it 'returns 3 seconds as seconds' do
|
208
|
+
seconds = 3 * 60 * 60 * 24 * 7
|
209
|
+
expect(3.week).to eq(seconds)
|
210
|
+
expect(3.weeks).to eq(seconds)
|
211
|
+
end
|
212
|
+
|
213
|
+
it 'returns 75.6 weeks as seconds' do
|
214
|
+
seconds = 75.6 * 60 * 60 * 24 * 7
|
215
|
+
expect(75.6.week).to eq(seconds)
|
216
|
+
expect(75.6.weeks).to eq(seconds)
|
217
|
+
end
|
218
|
+
|
219
|
+
it 'returns -2 weeks as seconds' do
|
220
|
+
seconds = -2 * 60 * 60 * 24 * 7
|
221
|
+
expect(-2.week).to eq(seconds)
|
222
|
+
expect(-2.weeks).to eq(seconds)
|
223
|
+
end
|
224
|
+
|
225
|
+
it 'returns -2.7 weeks as seconds' do
|
226
|
+
seconds = -2.7 * 60 * 60 * 24 * 7
|
227
|
+
expect(-2.7.week).to eq(seconds)
|
228
|
+
expect(-2.7.weeks).to eq(seconds)
|
229
|
+
end
|
230
|
+
end
|
231
|
+
end
|
data/timeloop.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'timeloop/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "timeloop"
|
8
|
+
spec.version = Timeloop::VERSION
|
9
|
+
spec.authors = ['Maciej Paruszewski']
|
10
|
+
spec.email = ['maciek.paruszewski@gmail.com']
|
11
|
+
spec.summary = %q{Timeloop is a simple Ruby gem that provides loop with time interval.}
|
12
|
+
spec.homepage = 'https://github.com/pinoss/timeloop'
|
13
|
+
spec.license = 'MIT'
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ['lib']
|
19
|
+
|
20
|
+
spec.add_development_dependency 'bundler', "~> 1.6"
|
21
|
+
spec.add_development_dependency 'rake'
|
22
|
+
spec.add_development_dependency 'rspec'
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: timeloop
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Maciej Paruszewski
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-07-16 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: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
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
|
+
description:
|
56
|
+
email:
|
57
|
+
- maciek.paruszewski@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- .gitignore
|
63
|
+
- .rspec
|
64
|
+
- .travis.yml
|
65
|
+
- Gemfile
|
66
|
+
- LICENSE.txt
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- lib/timeloop.rb
|
70
|
+
- lib/timeloop/core_ext.rb
|
71
|
+
- lib/timeloop/core_ext/integer.rb
|
72
|
+
- lib/timeloop/core_ext/integer/time.rb
|
73
|
+
- lib/timeloop/core_ext/numeric.rb
|
74
|
+
- lib/timeloop/core_ext/numeric/time.rb
|
75
|
+
- lib/timeloop/every.rb
|
76
|
+
- lib/timeloop/version.rb
|
77
|
+
- spec/spec_helper.rb
|
78
|
+
- spec/unit/core_ext/integer_spec.rb
|
79
|
+
- spec/unit/core_ext/numeric_spec.rb
|
80
|
+
- timeloop.gemspec
|
81
|
+
homepage: https://github.com/pinoss/timeloop
|
82
|
+
licenses:
|
83
|
+
- MIT
|
84
|
+
metadata: {}
|
85
|
+
post_install_message:
|
86
|
+
rdoc_options: []
|
87
|
+
require_paths:
|
88
|
+
- lib
|
89
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ! '>='
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
requirements: []
|
100
|
+
rubyforge_project:
|
101
|
+
rubygems_version: 2.2.2
|
102
|
+
signing_key:
|
103
|
+
specification_version: 4
|
104
|
+
summary: Timeloop is a simple Ruby gem that provides loop with time interval.
|
105
|
+
test_files:
|
106
|
+
- spec/spec_helper.rb
|
107
|
+
- spec/unit/core_ext/integer_spec.rb
|
108
|
+
- spec/unit/core_ext/numeric_spec.rb
|