module FakeZip::Helpers
Public Instance Methods
collect_all(given)
click to toggle source
# File lib/fake_zip.rb, line 32 def collect_all(given) found = [] traverse given do |x,y| found << [x,y] end found end
collect_only(given, kind)
click to toggle source
# File lib/fake_zip.rb, line 37 def collect_only(given, kind) collect_all(given).map { |(name,type)| name if type == kind }.compact end
dirs(given)
click to toggle source
# File lib/fake_zip.rb, line 43 def dirs(given) collect_only(given, :dir).map { |x| x.join ?/ } end
files(given)
click to toggle source
# File lib/fake_zip.rb, line 40 def files(given) collect_only(given, :file).map { |x| x.join ?/ } end
traverse(array_or_hash, path=[], &block)
click to toggle source
# File lib/fake_zip.rb, line 18 def traverse array_or_hash, path=[], &block given = array_or_hash case given when Hash given.each_pair do |k,v| block.call path+[k], :dir # entering directory traverse v,path+[k],&block end when Array then given.each { |x| traverse x,path,&block } else block.call path+[given], :file end end