array_groupings 0.0.1 → 0.0.2
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.
- data/VERSION +1 -1
- data/array_groupings.gemspec +2 -2
- data/lib/array_groupings.rb +37 -35
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.2
|
data/array_groupings.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{array_groupings}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Kasper Johansen"]
|
12
|
-
s.date = %q{2012-06-
|
12
|
+
s.date = %q{2012-06-28}
|
13
13
|
s.description = %q{[1, 2, 4, 5] #~> [[1, 2], [2, 4], [4, 5]]}
|
14
14
|
s.email = %q{k@spernj.org}
|
15
15
|
s.extra_rdoc_files = [
|
data/lib/array_groupings.rb
CHANGED
@@ -1,55 +1,57 @@
|
|
1
1
|
class Array_groupings
|
2
2
|
def initialize(args)
|
3
3
|
@args = args
|
4
|
-
@arr = @args[:arr]
|
4
|
+
@arr = @args[:arr].to_enum
|
5
5
|
@debug = @args[:debug]
|
6
6
|
end
|
7
7
|
|
8
8
|
def parse
|
9
9
|
return Enumerator.new do |yielder|
|
10
|
-
prev_ele = @arr.
|
10
|
+
prev_ele = @arr.next
|
11
11
|
chunk = [prev_ele]
|
12
12
|
chunks = [chunk]
|
13
13
|
print "First ele: #{prev_ele}\n" if @debug
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
chunks.each do |chunk_i|
|
21
|
-
res_last = yield(chunk_i.last, ele)
|
22
|
-
res_first = yield(chunk_i.first, ele)
|
15
|
+
begin
|
16
|
+
while ele = @arr.next
|
17
|
+
print "Ele: '#{ele}'\n" if @debug
|
18
|
+
deletes = []
|
19
|
+
adds = []
|
23
20
|
|
24
|
-
|
25
|
-
chunk_i
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
21
|
+
chunks.each do |chunk_i|
|
22
|
+
res_last = yield(chunk_i.last, ele)
|
23
|
+
res_first = yield(chunk_i.first, ele)
|
24
|
+
|
25
|
+
if res_first and res_last
|
26
|
+
chunk_i << ele
|
27
|
+
elsif !res_last and !res_first
|
28
|
+
yielder << chunk_i
|
29
|
+
deletes << chunk_i
|
30
|
+
adds << [ele]
|
31
|
+
elsif res_last and !res_first
|
32
|
+
new_add = []
|
33
|
+
chunk_i.each do |chunk_i_ele|
|
34
|
+
if yield(chunk_i_ele, ele)
|
35
|
+
new_add << chunk_i_ele
|
36
|
+
end
|
35
37
|
end
|
38
|
+
new_add << ele
|
39
|
+
|
40
|
+
yielder << chunk_i
|
41
|
+
adds << new_add
|
42
|
+
deletes << chunk_i
|
43
|
+
else
|
44
|
+
raise "Dont know what to do here. First: #{chunk_i.first}, last: #{chunk_i.last}, ele: #{ele}, res_last: #{res_last}, res_first: #{res_first}"
|
36
45
|
end
|
37
|
-
new_add << ele
|
38
|
-
|
39
|
-
yielder << chunk_i
|
40
|
-
adds << new_add
|
41
|
-
deletes << chunk_i
|
42
|
-
else
|
43
|
-
raise "Dont know what to do here..."
|
44
46
|
end
|
47
|
+
|
48
|
+
chunks -= deletes
|
49
|
+
chunks += adds
|
50
|
+
end
|
51
|
+
rescue StopIteration
|
52
|
+
chunks.each do |chunk|
|
53
|
+
yielder << chunk
|
45
54
|
end
|
46
|
-
|
47
|
-
chunks -= deletes
|
48
|
-
chunks += adds
|
49
|
-
end
|
50
|
-
|
51
|
-
chunks.each do |chunk|
|
52
|
-
yielder << chunk
|
53
55
|
end
|
54
56
|
end
|
55
57
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: array_groupings
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.2
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Kasper Johansen
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2012-06-
|
13
|
+
date: 2012-06-28 00:00:00 +02:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -103,7 +103,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
103
103
|
requirements:
|
104
104
|
- - ">="
|
105
105
|
- !ruby/object:Gem::Version
|
106
|
-
hash:
|
106
|
+
hash: 3888694577287435389
|
107
107
|
segments:
|
108
108
|
- 0
|
109
109
|
version: "0"
|