Class: Raz::DirEntry

Inherits:
Object
  • Object
show all
Defined in:
lib/raz/entries.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, absolute_path) ⇒ DirEntry

Returns a new instance of DirEntry.

Parameters:

  • name (String)


68
69
70
71
72
73
# File 'lib/raz/entries.rb', line 68

def initialize(name, absolute_path)
  @name            = name
  @absolute_path   = absolute_path
  @entries         = {}
  @ignored_entries = {}
end

Instance Attribute Details

#absolute_pathString (readonly)

Returns:

  • (String)


64
65
66
# File 'lib/raz/entries.rb', line 64

def absolute_path
  @absolute_path
end

#entriesHash<String, FileEntry | DirEntry>

Returns:



52
53
54
# File 'lib/raz/entries.rb', line 52

def entries
  @entries
end

#ignored_entriesHash<String, FileEntry | DirEntry>

Returns:



56
57
58
# File 'lib/raz/entries.rb', line 56

def ignored_entries
  @ignored_entries
end

#nameString (readonly)

Returns:

  • (String)


60
61
62
# File 'lib/raz/entries.rb', line 60

def name
  @name
end

Instance Method Details

#==(other) ⇒ Object



83
84
85
# File 'lib/raz/entries.rb', line 83

def ==(other)
  name == other.name && entries == other.entries
end

#[](key) ⇒ Object



75
76
77
# File 'lib/raz/entries.rb', line 75

def [](key)
  @entries[key]
end

#[]=(key, value) ⇒ Object



79
80
81
# File 'lib/raz/entries.rb', line 79

def []=(key, value)
  @entries[key] = value
end

#dir_entriesHash<String, FileEntry | DirEntry>

Returns:



99
100
101
# File 'lib/raz/entries.rb', line 99

def dir_entries
  entries.select { |_k, v| v.is_a?(DirEntry) }
end

#file_entriesHash<String, FileEntry | DirEntry>

Returns:



105
106
107
# File 'lib/raz/entries.rb', line 105

def file_entries
  entries.select { |_k, v| v.is_a?(FileEntry) }
end

#recursive_entriesArray<FileEntry | DirEntry>

Returns:



111
112
113
114
115
116
117
118
# File 'lib/raz/entries.rb', line 111

def recursive_entries
  all_entries = []

  all_entries += entries.values
  all_entries += dir_entries.values.flat_map(&:recursive_entries)

  all_entries
end

#recursive_ignored_empty?Bool

Returns:

  • (Bool)


89
90
91
92
93
94
95
# File 'lib/raz/entries.rb', line 89

def recursive_ignored_empty?
  return false unless ignored_entries.empty?

  dir_entries.all? do |key, entry|
    entry.recursive_ignored_empty?
  end
end