Class: Glob::Matcher
- Inherits:
-
Object
- Object
- Glob::Matcher
- Defined in:
- lib/glob/matcher.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#regex ⇒ Object
readonly
Returns the value of attribute regex.
Instance Method Summary collapse
- #include? ⇒ Boolean
-
#initialize(path) ⇒ Matcher
constructor
A new instance of Matcher.
- #match?(other) ⇒ Boolean
- #process_group(group) ⇒ Object
- #reject? ⇒ Boolean
Constructor Details
#initialize(path) ⇒ Matcher
Returns a new instance of Matcher.
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/glob/matcher.rb', line 7 def initialize(path) @path = path @reject = path.start_with?("!") pattern = Regexp.escape(path.gsub(/^!/, "")) .gsub(/(\\{.*?\\})/) {|match| process_group(match) } .gsub("\\*", "[^.]+") anchor = path.end_with?("*") ? "" : "$" @regex = Regexp.new("^#{pattern}#{anchor}") end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
5 6 7 |
# File 'lib/glob/matcher.rb', line 5 def path @path end |
#regex ⇒ Object (readonly)
Returns the value of attribute regex.
5 6 7 |
# File 'lib/glob/matcher.rb', line 5 def regex @regex end |
Instance Method Details
#include? ⇒ Boolean
22 23 24 |
# File 'lib/glob/matcher.rb', line 22 def include? !reject? end |
#match?(other) ⇒ Boolean
18 19 20 |
# File 'lib/glob/matcher.rb', line 18 def match?(other) other.match?(regex) end |
#process_group(group) ⇒ Object
30 31 32 33 34 |
# File 'lib/glob/matcher.rb', line 30 def process_group(group) group = group.gsub(/[{}\\]/, "").split(",").join("|") "(#{group})" end |
#reject? ⇒ Boolean
26 27 28 |
# File 'lib/glob/matcher.rb', line 26 def reject? @reject end |