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 if entry
end

#==(other) ⇒ Object


51
52
53
54
# File 'lib/zip/entry_set.rb', line 51

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

#delete(entry) ⇒ Object


32
33
34
# File 'lib/zip/entry_set.rb', line 32

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

#dupObject

deep clone


47
48
49
# File 'lib/zip/entry_set.rb', line 47

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

#eachObject


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

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

#entriesObject


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

def entries
  sorted_entries.values
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 | ::File::FNM_EXTGLOB) ⇒ Object


60
61
62
63
64
65
66
# File 'lib/zip/entry_set.rb', line 60

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)

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

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

#parent(entry) ⇒ Object


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

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