array_enumerator 0.0.6 → 0.0.7

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: 69448f28caa793c6b65a60b298fe11fa2ac57d7c
4
- data.tar.gz: ed8e36e4a408788d181f8cc3ac69ec7153dfa3d2
3
+ metadata.gz: d86472c1fa158b7a9188e0858ff624e3d11b4e54
4
+ data.tar.gz: 2533a69707036ee1b7bb35dd16ef82d79e68292a
5
5
  SHA512:
6
- metadata.gz: e3344e03d49a23806f940847ede0411d21b3650fce45875259d2a4fe97cbaf146d815197d50e75f6e9d46f0434702810fe354599d90ee668e7daaff0ecd6820a
7
- data.tar.gz: fdd8f72373942879ab83ff7f56b1a8b57d6d1a05a7450fb14e742e5b307609ad563b938b7df4d226590933215d927bef915cdc8094d3afdbadd2e7ea010ff145
6
+ metadata.gz: 3f81050595e5c143a22ed32a2380e84d3eb256abed8ab9ac72b16fb9aeb13a601c4ae30394f6fef0bb8a2008ff0c59ea2c80b7c3986e3fdebfd1273ddbe11ecc
7
+ data.tar.gz: 0074841d43c186559c64bc06f7e1310c29619050436ba36bfceb4c1b2099ad16b120429d3a929d3c9716cb7b22121c0192c38f96fc73f9595e3650af82a603d5
data/README.md CHANGED
@@ -24,6 +24,17 @@ a_enum = ArrayEnumerator.new do |y|
24
24
  end
25
25
  ```
26
26
 
27
+ Or give it a normal Enumerator that already exists:
28
+ ```ruby
29
+ enum = Enumerator.new do |y|
30
+ 1_000.times do |count|
31
+ y << count
32
+ end
33
+ end
34
+
35
+ a_enum = ArrayEnumerator.new(enum)
36
+ ```
37
+
27
38
  Call array-methods like you normally would:
28
39
  ```ruby
29
40
  a_enum.empty? #=> false
@@ -32,6 +43,17 @@ a_enum.shift #=> 2
32
43
  a_enum[2] #=> 3
33
44
  a_enum.each_index { |count| puts "Count: #{count}" }
34
45
  a_enum.length #=> 3
46
+ results_array = a_enum.select { |element| element.something? }
47
+ ```
48
+
49
+ ### Collect
50
+
51
+ Prints out 100, 101 102 etc.
52
+ ```ruby
53
+ collected_a_enum = a_enum.collect { |count| count + 100 }
54
+ collected_a_enum.each do |count|
55
+ print "#{count} "
56
+ end
35
57
  ```
36
58
 
37
59
  ## Contributing to ArrayEnumerator
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.6
1
+ 0.0.7
@@ -182,6 +182,18 @@ class ArrayEnumerator
182
182
  return res
183
183
  end
184
184
 
185
+ def collect
186
+ check_corrupted
187
+
188
+ return ArrayEnumerator.new do |y|
189
+ self.each do |element|
190
+ y << yield(element)
191
+ end
192
+ end
193
+ end
194
+
195
+ alias map collect
196
+
185
197
  # Returns a normal array with all elements. Can also raise corrupted error if elements have been thrown out.
186
198
  def to_a
187
199
  check_corrupted
@@ -1,6 +1,14 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe "ArrayEnumerator" do
4
+ let(:a_enum_10) do
5
+ ArrayEnumerator.new do |y|
6
+ 10.times do |count|
7
+ y << count
8
+ end
9
+ end
10
+ end
11
+
4
12
  it "can be initialized as normal enumerator" do
5
13
  enum = ArrayEnumerator.new do |y|
6
14
  3.times do |count|
@@ -131,4 +139,30 @@ describe "ArrayEnumerator" do
131
139
  result = enum.select { |element| element == 5}
132
140
  result.should eq [5]
133
141
  end
142
+
143
+ describe "#collect" do
144
+ it "should return a new enumerator yielding the new values one by one" do
145
+ collected_a_enum = a_enum_10.collect { |element| element + 1000 }
146
+
147
+ count = 0
148
+ collected_a_enum.each do |number|
149
+ number.should eq (count + 1000)
150
+ count += 1
151
+ end
152
+
153
+ count.should eq 10
154
+ end
155
+
156
+ it "should work with map and block-symbols" do
157
+ collected_a_enum = a_enum_10.map(&:to_f)
158
+
159
+ count = 0
160
+ collected_a_enum.each do |number|
161
+ number.should eq count.to_f
162
+ count += 1
163
+ end
164
+
165
+ count.should eq 10
166
+ end
167
+ end
134
168
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: array_enumerator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kasper Johansen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-21 00:00:00.000000000 Z
11
+ date: 2015-02-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec