Module: Picoglob
- Defined in:
- lib/picoglob.rb,
lib/picoglob/version.rb,
lib/picoglob/compiler.rb
Overview
Picoglob compiles bash-style glob patterns into Ruby Regexps so you can match *arbitrary strings* — S3 keys, routes, log lines, branch names — not just files on disk.
It’s the missing Ruby counterpart to JS’s picomatch / minimatch. Ruby ships ‘File.fnmatch` and `Dir.glob`, but neither gives you a reusable `Regexp`, and `File.fnmatch` has limited brace/extglob support that’s awkward to use off the filesystem.
Defined Under Namespace
Classes: Compiler, Matcher, ParseError
Constant Summary collapse
- VERSION =
"0.1.0"
Class Method Summary collapse
-
.filter(pattern, strings, **opts) ⇒ Array<String>
Convenience: keep only the strings that match
pattern. -
.match?(pattern, string, **opts) ⇒ Boolean
Convenience: does
stringmatchpattern?. -
.new(pattern, **opts) ⇒ Picoglob::Matcher
Build a reusable matcher.
-
.to_regexp(pattern, **opts) ⇒ Regexp
Convenience: compile
patternto a Regexp.
Class Method Details
.filter(pattern, strings, **opts) ⇒ Array<String>
Convenience: keep only the strings that match pattern.
55 56 57 |
# File 'lib/picoglob.rb', line 55 def self.filter(pattern, strings, **opts) Matcher.new(pattern, **opts).filter(strings) end |
.match?(pattern, string, **opts) ⇒ Boolean
Convenience: does string match pattern?
43 44 45 |
# File 'lib/picoglob.rb', line 43 def self.match?(pattern, string, **opts) Matcher.new(pattern, **opts).match?(string) end |
.new(pattern, **opts) ⇒ Picoglob::Matcher
Build a reusable matcher.
37 38 39 |
# File 'lib/picoglob.rb', line 37 def self.new(pattern, **opts) Matcher.new(pattern, **opts) end |