Class: Omnizip::Extraction::GlobPattern

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

Overview

Implements glob pattern matching for file paths

Supports:

      • Match any characters except /
  • ** - Match any characters including /
  • ? - Match single character
  • [abc] - Character class
  • [!abc] - Negated character class
  • a,b,c - Alternation (brace expansion)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pattern) ⇒ GlobPattern

Initialize a new glob pattern

Parameters:

  • pattern (String)

    Glob pattern string



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

def initialize(pattern)
  @pattern = pattern.to_s
  @regex = compile_pattern
end

Instance Attribute Details

#patternObject (readonly)

Returns the value of attribute pattern.



15
16
17
# File 'lib/omnizip/extraction/glob_pattern.rb', line 15

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)


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

def match?(filename)
  @regex.match?(filename.to_s)
end

#to_sString

Convert pattern to string

Returns:

  • (String)


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

def to_s
  @pattern
end