ev/tree.rb in rwdtinker-1.67 vs ev/tree.rb in rwdtinker-1.68
- old
+ new
@@ -86,18 +86,46 @@
end
def inspect
parent, children = @parent, @children
- @parent, @children = parent.id, children.collect{|obj| obj.id}
+ @parent, @children = parent.object_id, children.collect{|obj| obj.object_id}
res = " " * (level-1) + "#{self.class}(#{@subtype}) #{super}"
@parent, @children = parent, children
res
end
+
+ def previous(klass=[], skip=[])
+ klass = [klass].flatten
+ skip = [skip].flatten
+
+ po = @parent
+ return nil if po.nil?
+
+ ch = po.children
+ return nil if ch.nil?
+
+ n = ch.index(self)
+ return nil if n.nil?
+
+ res = nil
+ if klass.nil?
+ n -= 1
+ res = ch[n]
+ else
+ begin
+ n -= 1
+ res = ch[n]
+ end while (klass.empty? or klass.collect{|k| ch[n-1].kind_of?(k)}.sort.uniq == [true]) \
+ and (skip.empty? or skip.collect{|k| ch[n-1].kind_of?(k)}.sort.uniq == [false])
+ end
+
+ res
+ end
end
class Tree
@@versie = 1
@@mutex = Mutex.new
@@ -136,11 +164,11 @@
def self.file(file)
new(File.new(file).readlines)
end
def self.location(url, form=Hash.new)
- s = HTTPClient.get(url, form)
+ s = HTTPClient.get(url, {}, form)
s = "" if s.nil?
new(s)
end
def self.new_from_cache2(data)
@@ -153,11 +181,11 @@
dir = "#{temp}/evcache.#{user}/tree.new"
file = "#{dir}/#{hash}"
tree = nil
- Dir.mkdirrec(dir)
+ File.mkpath(dir)
if File.file?(file)
@@mutex.synchronize do
tree = Marshal.restore(File.new(file, "rb"))
end
@@ -225,21 +253,21 @@
end
end
end
def markclosed
- ([self].concat @objects).each do |obj|
+ ([self] + @objects).each do |obj|
obj.children.each_index do |i|
co1 = obj.children[i]
co2 = obj.children[i+1]
co1.closed = (not co2.nil? and co1.upordown == Down and (co2.upordown == Up or co2.upordown == Dummy) and co1.subtype == co2.subtype)
end
end
end
def deletedummies
- ([self].concat @objects).each do |obj|
+ ([self] + @objects).each do |obj|
obj.children.delete_if do |obj2|
obj2.upordown == Dummy
end
end