Class: PathFilter::Trie

Inherits:
Struct
  • Object
show all
Defined in:
lib/path_filter.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#childrenObject

Returns the value of attribute children

Returns:

  • (Object)

    the current value of children



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

def children
  @children
end

#matchedObject

Returns the value of attribute matched

Returns:

  • (Object)

    the current value of matched



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

def matched
  @matched
end

Class Method Details

.from_paths(paths) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/path_filter.rb', line 5

def self.from_paths(paths)
  root = Trie.node
  root.matched = true if paths.empty?

  paths.each do |path|
    trie = root
    path.each_filename { |name| trie = trie.children[name] }
    trie.matched = true
  end

  root
end

.nodeObject



18
19
20
# File 'lib/path_filter.rb', line 18

def self.node
  Trie.new(false, Hash.new { |hash, key| hash[key] = Trie.node })
end