rubyzip/lib/zip/zip_entry_set.rb

67 lines
1.3 KiB
Ruby
Executable File

module Zip
class ZipEntrySet #:nodoc:all
include Enumerable
def initialize(anEnumerable = [])
super()
@entrySet = {}
anEnumerable.each { |o| push(o) }
end
def include?(entry)
@entrySet.include?(entry.to_s)
end
def <<(entry)
@entrySet[entry.to_s] = entry
end
alias :push :<<
def size
@entrySet.size
end
alias :length :size
def delete(entry)
@entrySet.delete(entry.to_s) ? entry : nil
end
def each(&aProc)
@entrySet.values.each(&aProc)
end
def entries
@entrySet.values
end
# deep clone
def dup
ZipEntrySet.new(@entrySet.values.map { |e| e.dup })
end
def ==(other)
return false unless other.kind_of?(ZipEntrySet)
@entrySet == other.entrySet
end
def parent(entry)
@entrySet[entry.parent_as_string]
end
def glob(pattern, flags = ::File::FNM_PATHNAME|::File::FNM_DOTMATCH)
entries.select do |entry|
::File.fnmatch(pattern, entry.name.chomp('/'), flags)
end
end
#TODO attr_accessor :auto_create_directories
protected
attr_accessor :entrySet
end
end
# Copyright (C) 2002, 2003 Thomas Sondergaard
# rubyzip is free software; you can redistribute it and/or
# modify it under the terms of the ruby license.