Class: Omnizip::Extraction::FilterChain
- Inherits:
-
Object
- Object
- Omnizip::Extraction::FilterChain
- Defined in:
- lib/omnizip/extraction/filter_chain.rb
Overview
Combines multiple pattern matchers with AND/OR logic
Supports include and exclude patterns, allowing complex filtering scenarios like "all .rb files except in test/".
Instance Attribute Summary collapse
-
#exclude_patterns ⇒ Object
readonly
Returns the value of attribute exclude_patterns.
-
#exclude_predicates ⇒ Object
readonly
Returns the value of attribute exclude_predicates.
-
#include_patterns ⇒ Object
readonly
Returns the value of attribute include_patterns.
-
#include_predicates ⇒ Object
readonly
Returns the value of attribute include_predicates.
Instance Method Summary collapse
-
#any? ⇒ Boolean
Check if chain has any conditions.
-
#count ⇒ Integer
Get count of all conditions.
-
#exclude {|entry| ... } ⇒ self
Add an exclude predicate.
-
#exclude_pattern(pattern) ⇒ self
Add an exclude pattern.
-
#filter(entries) ⇒ Array
Filter an array of entries.
-
#include {|entry| ... } ⇒ self
Add an include predicate.
-
#include_pattern(pattern) ⇒ self
Add an include pattern.
-
#initialize ⇒ FilterChain
constructor
Initialize a new filter chain.
-
#match?(entry, filename: nil) ⇒ Boolean
Check if an entry matches the filter chain.
Constructor Details
#initialize ⇒ FilterChain
Initialize a new filter chain
14 15 16 17 18 19 |
# File 'lib/omnizip/extraction/filter_chain.rb', line 14 def initialize @include_patterns = [] @exclude_patterns = [] @include_predicates = [] @exclude_predicates = [] end |
Instance Attribute Details
#exclude_patterns ⇒ Object (readonly)
Returns the value of attribute exclude_patterns.
10 11 12 |
# File 'lib/omnizip/extraction/filter_chain.rb', line 10 def exclude_patterns @exclude_patterns end |
#exclude_predicates ⇒ Object (readonly)
Returns the value of attribute exclude_predicates.
10 11 12 |
# File 'lib/omnizip/extraction/filter_chain.rb', line 10 def exclude_predicates @exclude_predicates end |
#include_patterns ⇒ Object (readonly)
Returns the value of attribute include_patterns.
10 11 12 |
# File 'lib/omnizip/extraction/filter_chain.rb', line 10 def include_patterns @include_patterns end |
#include_predicates ⇒ Object (readonly)
Returns the value of attribute include_predicates.
10 11 12 |
# File 'lib/omnizip/extraction/filter_chain.rb', line 10 def include_predicates @include_predicates end |
Instance Method Details
#any? ⇒ Boolean
Check if chain has any conditions
90 91 92 93 94 95 |
# File 'lib/omnizip/extraction/filter_chain.rb', line 90 def any? !@include_patterns.empty? || !@exclude_patterns.empty? || !@include_predicates.empty? || !@exclude_predicates.empty? end |
#count ⇒ Integer
Get count of all conditions
100 101 102 103 104 105 |
# File 'lib/omnizip/extraction/filter_chain.rb', line 100 def count @include_patterns.size + @exclude_patterns.size + @include_predicates.size + @exclude_predicates.size end |
#exclude {|entry| ... } ⇒ self
Add an exclude predicate
54 55 56 57 |
# File 'lib/omnizip/extraction/filter_chain.rb', line 54 def exclude(&predicate) @exclude_predicates << predicate if predicate self end |
#exclude_pattern(pattern) ⇒ self
Add an exclude pattern
34 35 36 37 |
# File 'lib/omnizip/extraction/filter_chain.rb', line 34 def exclude_pattern(pattern) @exclude_patterns << PatternMatcher.new(pattern) self end |
#filter(entries) ⇒ Array
Filter an array of entries
83 84 85 |
# File 'lib/omnizip/extraction/filter_chain.rb', line 83 def filter(entries) entries.select { |entry| match?(entry) } end |
#include {|entry| ... } ⇒ self
Add an include predicate
44 45 46 47 |
# File 'lib/omnizip/extraction/filter_chain.rb', line 44 def include(&predicate) @include_predicates << predicate if predicate self end |
#include_pattern(pattern) ⇒ self
Add an include pattern
25 26 27 28 |
# File 'lib/omnizip/extraction/filter_chain.rb', line 25 def include_pattern(pattern) @include_patterns << PatternMatcher.new(pattern) self end |
#match?(entry, filename: nil) ⇒ Boolean
Check if an entry matches the filter chain
Logic:
- If no includes, everything passes (except excludes)
- If includes exist, entry must match at least one include
- Entry must not match any exclude
69 70 71 72 73 74 75 76 77 |
# File 'lib/omnizip/extraction/filter_chain.rb', line 69 def match?(entry, filename: nil) name = filename || extract_filename(entry) # Check excludes first (faster to reject) return false if excluded?(entry, name) # Check includes included?(entry, name) end |