time-iterator 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +2 -0
- data/Gemfile +6 -0
- data/HISTORY.md +5 -0
- data/README.md +7 -0
- data/lib/time_iterator.rb +3 -5
- data/lib/time_iterator/version.rb +1 -1
- data/spec/lib/time_iterator_spec.rb +20 -9
- metadata +4 -3
data/.travis.yml
ADDED
data/Gemfile
CHANGED
data/HISTORY.md
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
# TimeIterator
|
2
2
|
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/time-iterator.png)](http://badge.fury.io/rb/time-iterator)
|
4
|
+
[![Build Status](https://secure.travis-ci.org/vid-io/time-iterator.png)](http://travis-ci.org/vid-io/time-iterator)
|
5
|
+
[![Dependency Status](https://gemnasium.com/vid-io/time-iterator.png)](https://gemnasium.com/vid-io/time-iterator)
|
6
|
+
[![Code Climate](https://codeclimate.com/github/vid-io/time-iterator.png)](https://codeclimate.com/github/vid-io/time-iterator)
|
7
|
+
[![Coverage Status](https://coveralls.io/repos/vid-io/time-iterator/badge.png)](https://coveralls.io/r/vid-io/time-iterator)
|
8
|
+
|
9
|
+
|
3
10
|
Utility class to iterate through times with a given step size.
|
4
11
|
|
5
12
|
|
data/lib/time_iterator.rb
CHANGED
@@ -32,17 +32,15 @@ class TimeIterator
|
|
32
32
|
# @yield [time]
|
33
33
|
# @return [TimeIterator]
|
34
34
|
def each &block
|
35
|
-
|
36
|
-
curr = @start + 0
|
35
|
+
curr = @start + 0
|
37
36
|
|
37
|
+
if @start < @stop
|
38
38
|
while curr <= @stop
|
39
39
|
yield curr
|
40
40
|
curr += @step
|
41
41
|
end
|
42
42
|
else
|
43
|
-
curr
|
44
|
-
|
45
|
-
while curr >= @start
|
43
|
+
while curr >= @stop
|
46
44
|
yield curr
|
47
45
|
curr -= @step
|
48
46
|
end
|
@@ -3,21 +3,32 @@ require "spec_helper"
|
|
3
3
|
|
4
4
|
describe TimeIterator do
|
5
5
|
|
6
|
-
let(:start) { Time.now - 60 }
|
7
|
-
let(:stop) { start + 60 }
|
8
|
-
let(:iter) { TimeIterator.new start, stop, 30 }
|
9
|
-
|
10
|
-
|
11
6
|
it "should include Enumerable" do
|
12
|
-
|
7
|
+
TimeIterator.new(Time.now, Time.now).should be_kind_of Enumerable
|
13
8
|
end
|
14
9
|
|
15
10
|
|
16
11
|
context "#each" do
|
17
|
-
|
18
|
-
|
19
|
-
|
12
|
+
let(:pivot) { Time.utc(1970, 1, 1) }
|
13
|
+
|
14
|
+
context "when since < till" do
|
15
|
+
let(:iter) { TimeIterator.new pivot, pivot + 60, 30 }
|
16
|
+
|
17
|
+
it "should yield every Time stop ascending" do
|
18
|
+
lambda{ |b| iter.each(&b) }
|
19
|
+
.should yield_successive_args(pivot, pivot + 30, pivot + 60)
|
20
|
+
end
|
20
21
|
end
|
22
|
+
|
23
|
+
context "when since > till" do
|
24
|
+
let(:iter) { TimeIterator.new pivot + 60, pivot, 30 }
|
25
|
+
|
26
|
+
it "should yield every Time stop descending" do
|
27
|
+
lambda{ |b| iter.each(&b) }
|
28
|
+
.should yield_successive_args(pivot + 60, pivot + 30, pivot)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
21
32
|
end
|
22
33
|
|
23
34
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: time-iterator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-05-
|
12
|
+
date: 2013-05-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -70,6 +70,7 @@ extra_rdoc_files: []
|
|
70
70
|
files:
|
71
71
|
- .gitignore
|
72
72
|
- .rspec
|
73
|
+
- .travis.yml
|
73
74
|
- Gemfile
|
74
75
|
- Guardfile
|
75
76
|
- HISTORY.md
|
@@ -108,7 +109,7 @@ rubyforge_project:
|
|
108
109
|
rubygems_version: 1.8.23
|
109
110
|
signing_key:
|
110
111
|
specification_version: 3
|
111
|
-
summary: time-iterator-0.1.
|
112
|
+
summary: time-iterator-0.1.1
|
112
113
|
test_files:
|
113
114
|
- spec/lib/time_iterator/core_ext_spec.rb
|
114
115
|
- spec/lib/time_iterator_spec.rb
|