Sha256: 262ee8c8cc6f77d5769e33468927a1c734636b85aab768a045ee9f1a7bfffcfa

Contents?: true

Size: 1.72 KB

Versions: 43

Compression:

Stored size: 1.72 KB

Contents

module Zip
  class EntrySet #:nodoc:all
    include Enumerable
    attr_accessor :entry_set, :entry_order

    def initialize(an_enumerable = [])
      super()
      @entry_set = {}
      an_enumerable.each { |o| push(o) }
    end

    def include?(entry)
      @entry_set.include?(to_key(entry))
    end

    def find_entry(entry)
      @entry_set[to_key(entry)]
    end

    def <<(entry)
      @entry_set[to_key(entry)] = entry if entry
    end

    alias push <<

    def size
      @entry_set.size
    end

    alias length size

    def delete(entry)
      entry if @entry_set.delete(to_key(entry))
    end

    def each
      @entry_set = sorted_entries.dup.each do |_, value|
        yield(value)
      end
    end

    def entries
      sorted_entries.values
    end

    # deep clone
    def dup
      EntrySet.new(@entry_set.values.map(&:dup))
    end

    def ==(other)
      return false unless other.kind_of?(EntrySet)

      @entry_set.values == other.entry_set.values
    end

    def parent(entry)
      @entry_set[to_key(entry.parent_as_string)]
    end

    def glob(pattern, flags = ::File::FNM_PATHNAME | ::File::FNM_DOTMATCH | ::File::FNM_EXTGLOB)
      entries.map do |entry|
        next nil unless ::File.fnmatch(pattern, entry.name.chomp('/'), flags)

        yield(entry) if block_given?
        entry
      end.compact
    end

    protected

    def sorted_entries
      ::Zip.sort_entries ? Hash[@entry_set.sort] : @entry_set
    end

    private

    def to_key(entry)
      k = entry.to_s.chomp('/')
      k.downcase! if ::Zip.case_insensitive_match
      k
    end
  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.

Version data entries

43 entries across 33 versions & 8 rubygems

Version Path
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/rubyzip-2.3.2/lib/zip/entry_set.rb
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/rubyzip-2.3.2/lib/zip/entry_set.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/rubyzip-2.3.2/lib/zip/entry_set.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/rubyzip-2.3.2/lib/zip/entry_set.rb
rubyzip-2.4.rc1 lib/zip/entry_set.rb
tdiary-5.2.4 vendor/bundle/ruby/3.1.0/gems/rubyzip-2.3.2/lib/zip/entry_set.rb
lg_pod_plugin-1.0.8 lib/zip/entry_set.rb
lg_pod_plugin-1.0.7 lib/zip/entry_set.rb
lg_pod_plugin-1.0.6 lib/zip/entry_set.rb
tdiary-5.2.3 vendor/bundle/ruby/3.1.0/gems/rubyzip-2.3.2/lib/zip/entry_set.rb
tdiary-5.2.2 vendor/bundle/ruby/3.1.0/gems/rubyzip-2.3.2/lib/zip/entry_set.rb
tdiary-5.2.1 vendor/bundle/ruby/3.1.0/gems/rubyzip-2.3.2/lib/zip/entry_set.rb
vagrant-unbundled-2.2.19.0 vendor/bundle/ruby/3.0.0/gems/rubyzip-2.3.2/lib/zip/entry_set.rb
tdiary-5.2.0 vendor/bundle/ruby/3.0.0/gems/rubyzip-2.3.2/lib/zip/entry_set.rb
tdiary-5.2.0 vendor/bundle/ruby/2.7.0/gems/rubyzip-2.3.0/lib/zip/entry_set.rb
date_n_time_picker_activeadmin-0.1.2 vendor/bundle/ruby/2.6.0/gems/rubyzip-2.3.2/lib/zip/entry_set.rb
date_n_time_picker_activeadmin-0.1.1 vendor/bundle/ruby/2.6.0/gems/rubyzip-2.3.2/lib/zip/entry_set.rb
vagrant-unbundled-2.2.18.0 vendor/bundle/ruby/3.0.0/gems/rubyzip-2.3.2/lib/zip/entry_set.rb
tdiary-5.1.7 vendor/bundle/ruby/3.0.0/gems/rubyzip-2.3.2/lib/zip/entry_set.rb
tdiary-5.1.7 vendor/bundle/ruby/2.7.0/gems/rubyzip-2.3.0/lib/zip/entry_set.rb