Class: Picoglob::Matcher
- Inherits:
-
Object
- Object
- Picoglob::Matcher
- Defined in:
- lib/picoglob.rb
Overview
A compiled glob. Compile once, match many times.
Instance Attribute Summary collapse
-
#pattern ⇒ String
readonly
The original glob pattern.
-
#regexp ⇒ Regexp
readonly
The compiled regular expression.
Instance Method Summary collapse
- #filter(strings) ⇒ Array<String>
-
#initialize(pattern, separator: "/", dot: false, extglob: true, nocase: false) ⇒ Matcher
constructor
A new instance of Matcher.
- #match?(string) ⇒ Boolean (also: #===)
- #to_regexp ⇒ Regexp
Constructor Details
#initialize(pattern, separator: "/", dot: false, extglob: true, nocase: false) ⇒ Matcher
Returns a new instance of Matcher.
66 67 68 69 70 71 |
# File 'lib/picoglob.rb', line 66 def initialize(pattern, separator: "/", dot: false, extglob: true, nocase: false) @pattern = pattern @regexp = Compiler.new( separator: separator, dot: dot, extglob: extglob, nocase: nocase ).compile(pattern) end |
Instance Attribute Details
#pattern ⇒ String (readonly)
Returns the original glob pattern.
62 63 64 |
# File 'lib/picoglob.rb', line 62 def pattern @pattern end |
#regexp ⇒ Regexp (readonly)
Returns the compiled regular expression.
64 65 66 |
# File 'lib/picoglob.rb', line 64 def regexp @regexp end |
Instance Method Details
#filter(strings) ⇒ Array<String>
87 88 89 |
# File 'lib/picoglob.rb', line 87 def filter(strings) strings.select { |s| @regexp.match?(s) } end |
#match?(string) ⇒ Boolean Also known as: ===
75 76 77 |
# File 'lib/picoglob.rb', line 75 def match?(string) @regexp.match?(string) end |
#to_regexp ⇒ Regexp
81 82 83 |
# File 'lib/picoglob.rb', line 81 def to_regexp @regexp end |