Class: Omnizip::Extraction::RegexPattern

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

Overview

Implements regex pattern matching for file paths

Wraps Ruby Regexp objects to provide consistent interface with other pattern types.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pattern) ⇒ RegexPattern

Initialize a new regex pattern

Parameters:

  • pattern (Regexp, String)

    Regex pattern



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

def initialize(pattern)
  @pattern = pattern.is_a?(Regexp) ? pattern : Regexp.new(pattern)
end

Instance Attribute Details

#patternObject (readonly)

Returns the value of attribute pattern.



10
11
12
# File 'lib/omnizip/extraction/regex_pattern.rb', line 10

def pattern
  @pattern
end

Instance Method Details

#match(filename) ⇒ MatchData?

Get match data for a filename

Parameters:

  • filename (String)

    Filename to check

Returns:

  • (MatchData, nil)


31
32
33
# File 'lib/omnizip/extraction/regex_pattern.rb', line 31

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

#match?(filename) ⇒ Boolean

Check if a filename matches the pattern

Parameters:

  • filename (String)

    Filename to check

Returns:

  • (Boolean)


23
24
25
# File 'lib/omnizip/extraction/regex_pattern.rb', line 23

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

#to_regexpRegexp

Get the underlying regex

Returns:

  • (Regexp)


45
46
47
# File 'lib/omnizip/extraction/regex_pattern.rb', line 45

def to_regexp
  @pattern
end

#to_sString

Convert pattern to string

Returns:

  • (String)


38
39
40
# File 'lib/omnizip/extraction/regex_pattern.rb', line 38

def to_s
  @pattern.source
end