Permalink
Browse files

Combined paths work now.

  • Loading branch information...
1 parent ba48c15 commit ec1e77a2f4c53c270bc800fcb90cba3cf58d5dd0 @pangloss committed Sep 28, 2012
Showing with 16 additions and 10 deletions.
  1. +16 −10 lib/pacer/transform/combined_path.rb
@@ -20,7 +20,7 @@ def attach_pipe(end_pipe)
end
- class CombinePathPipe < RubyPipe
+ class CombinePathPipe < Pacer::Pipes::RubyPipe
def initialize
super
self.building_path = nil
@@ -32,7 +32,7 @@ def processNextStart()
while true
path = starts.next
if building_path
- if path.first == building_path.first.first
+ if path.first == building_path.first
add_path path
else
return next_path(path)
@@ -43,7 +43,9 @@ def processNextStart()
end
rescue Pacer::EmptyPipe, java.util.NoSuchElementException
if building_path
- building_path
+ r = building_path
+ self.building_path = nil
+ r
else
raise EmptyPipe.instance
end
@@ -54,18 +56,22 @@ def processNextStart()
attr_accessor :building_path, :prev_path
def make(path)
- path.reverse.inject([]) { |inner, e| [e, inner] }
+ path.reverse.inject(nil) { |inner, e| [e, inner].compact }
end
def add_path(path)
working = building_path
- path.length.times do |pos|
+ (1..path.length).each do |pos|
current = path[pos]
prev = prev_path[pos]
if current == prev
working = working.last
else
- working << make(path[pos..-1])
+ if pos < path.length
+ working << make(path[pos..-1])
+ else
+ working << [current]
+ end
break
end
end
@@ -84,10 +90,10 @@ def next_path(path)
end
- [a [b [c]
- [d]]
- [e [f
- g]]]
+# [a [b [c]
+# [d]]
+# [e [f
+# g]]]

0 comments on commit ec1e77a

Please sign in to comment.