Class: Omnizip::Extraction::RegexPattern
- Inherits:
-
Object
- Object
- Omnizip::Extraction::RegexPattern
- 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
-
#pattern ⇒ Object
readonly
Returns the value of attribute pattern.
Instance Method Summary collapse
-
#initialize(pattern) ⇒ RegexPattern
constructor
Initialize a new regex pattern.
-
#match(filename) ⇒ MatchData?
Get match data for a filename.
-
#match?(filename) ⇒ Boolean
Check if a filename matches the pattern.
-
#to_regexp ⇒ Regexp
Get the underlying regex.
-
#to_s ⇒ String
Convert pattern to string.
Constructor Details
#initialize(pattern) ⇒ RegexPattern
Initialize a new 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
#pattern ⇒ Object (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
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
23 24 25 |
# File 'lib/omnizip/extraction/regex_pattern.rb', line 23 def match?(filename) @pattern.match?(filename.to_s) end |
#to_regexp ⇒ Regexp
Get the underlying regex
45 46 47 |
# File 'lib/omnizip/extraction/regex_pattern.rb', line 45 def to_regexp @pattern end |
#to_s ⇒ String
Convert pattern to string
38 39 40 |
# File 'lib/omnizip/extraction/regex_pattern.rb', line 38 def to_s @pattern.source end |