Class: Omnizip::Extraction::PatternMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/omnizip/extraction/pattern_matcher.rb

Overview

Coordinates pattern matching across different pattern types

Automatically detects pattern type and delegates to appropriate pattern implementation (glob, regex, or predicate).

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pattern) ⇒ PatternMatcher

Initialize a new pattern matcher

Parameters:

  • pattern (String, Regexp, Proc, Object)

    Pattern to match



13
14
15
# File 'lib/omnizip/extraction/pattern_matcher.rb', line 13

def initialize(pattern)
  @pattern = build_pattern(pattern)
end

Instance Attribute Details

#patternGlobPattern, ... (readonly)

Get the underlying pattern object



36
37
38
# File 'lib/omnizip/extraction/pattern_matcher.rb', line 36

def pattern
  @pattern
end

Instance Method Details

#match?(filename) ⇒ Boolean

Check if a filename matches the pattern

Parameters:

  • filename (String)

    Filename to check

Returns:

  • (Boolean)


21
22
23
# File 'lib/omnizip/extraction/pattern_matcher.rb', line 21

def match?(filename)
  @pattern.match?(filename)
end

#match_all(filenames) ⇒ Array<String>

Match against multiple filenames

Parameters:

  • filenames (Array<String>)

    Filenames to check

Returns:

  • (Array<String>)

    Matching filenames



29
30
31
# File 'lib/omnizip/extraction/pattern_matcher.rb', line 29

def match_all(filenames)
  filenames.select { |filename| match?(filename) }
end

#to_sString

Convert pattern to string

Returns:

  • (String)


41
42
43
# File 'lib/omnizip/extraction/pattern_matcher.rb', line 41

def to_s
  @pattern.to_s
end