module RealZip::Helpers

Public Instance Methods

collect_all(given) click to toggle source
# File lib/real_zip.rb, line 34
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/real_zip.rb, line 39
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/real_zip.rb, line 45
def dirs(given)
  collect_only(given, :dir).map { |x| x.join ?/ }
end
files(given) click to toggle source
# File lib/real_zip.rb, line 42
def files(given)
  collect_only(given, :file).map { |x| x.join ?/ }
end
is_file(file) click to toggle source
# File lib/real_zip.rb, line 49
def is_file(file)
  File.file?(file)
end
traverse(array_or_hash, path=[], &block) click to toggle source
# File lib/real_zip.rb, line 20
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