Class: Zip::EntrySet

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

Overview

:nodoc:all

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(an_enumerable = []) ⇒ EntrySet

Returns a new instance of EntrySet.


6
7
8
9
10
# File 'lib/zip/entry_set.rb', line 6

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

Instance Attribute Details

#entry_orderObject

Returns the value of attribute entry_order


4
5
6
# File 'lib/zip/entry_set.rb', line 4

def entry_order
  @entry_order
end

#entry_setObject

Returns the value of attribute entry_set


4
5
6
# File 'lib/zip/entry_set.rb', line 4

def entry_set
  @entry_set
end

Instance Method Details

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


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

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

#==(other) ⇒ Object


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

def ==(other)
  return false unless other.kind_of?(EntrySet)
  @entry_set.values == other.entry_set.values
end

#delete(entry) ⇒ Object


32
33
34
35
36
37
38
# File 'lib/zip/entry_set.rb', line 32

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

#dupObject

deep clone


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

def dup
  EntrySet.new(@entry_set.map { |key, value| value.dup })
end

#each(&block) ⇒ Object


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

def each(&block)
  @entry_set = @entry_set.dup.each do |_, value|
    block.call(value)
  end
end

#entriesObject


46
47
48
49
50
51
52
# File 'lib/zip/entry_set.rb', line 46

def entries
  if ::Zip.sort_entries == true
    @entry_set.values.sort_by{|x| x.name}
  else
    @entry_set.values
  end
end

#find_entry(entry) ⇒ Object


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

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

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


68
69
70
71
72
73
74
# File 'lib/zip/entry_set.rb', line 68

def glob(pattern, flags = ::File::FNM_PATHNAME|::File::FNM_DOTMATCH)
  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)

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

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

#parent(entry) ⇒ Object


64
65
66
# File 'lib/zip/entry_set.rb', line 64

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

#sizeObject Also known as: length


26
27
28
# File 'lib/zip/entry_set.rb', line 26

def size
  @entry_set.size
end