Class: Zip::EntrySet

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/zip/entry_set.rb

Overview

:nodoc:all

Instance Method Summary collapse

Constructor Details

#initialize(an_enumerable = []) ⇒ EntrySet

Returns a new instance of EntrySet.



10
11
12
13
14
# File 'lib/zip/entry_set.rb', line 10

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

Instance Method Details

#<<(entry) ⇒ Object Also known as: push



24
25
26
# File 'lib/zip/entry_set.rb', line 24

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

#==(other) ⇒ Object



53
54
55
56
57
# File 'lib/zip/entry_set.rb', line 53

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

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

#delete(entry) ⇒ Object



36
37
38
# File 'lib/zip/entry_set.rb', line 36

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

#dupObject

deep clone



49
50
51
# File 'lib/zip/entry_set.rb', line 49

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

#each(&block) ⇒ Object



40
41
42
# File 'lib/zip/entry_set.rb', line 40

def each(&block)
  entries.each(&block)
end

#entriesObject



44
45
46
# File 'lib/zip/entry_set.rb', line 44

def entries
  sorted_entries.values
end

#find_entry(entry) ⇒ Object



20
21
22
# File 'lib/zip/entry_set.rb', line 20

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

#glob(pattern, flags = ::File::FNM_PATHNAME | ::File::FNM_DOTMATCH | ::File::FNM_EXTGLOB) ⇒ Object



63
64
65
66
67
68
69
70
# File 'lib/zip/entry_set.rb', line 63

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

#include?(entry) ⇒ Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/zip/entry_set.rb', line 16

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

#parent(entry) ⇒ Object



59
60
61
# File 'lib/zip/entry_set.rb', line 59

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

#sizeObject Also known as: length



30
31
32
# File 'lib/zip/entry_set.rb', line 30

def size
  @entry_set.size
end