Module: Quaker::TagMatcher
- Defined in:
- lib/quaker/tag_matcher.rb
Class Method Summary collapse
- .match(tags, patterns) ⇒ Object
- .pattern_matches_string?(s, pattern) ⇒ Boolean
- .wildcard_matches?(s, pattern) ⇒ Boolean
Class Method Details
.match(tags, patterns) ⇒ Object
3 4 5 6 7 8 9 10 |
# File 'lib/quaker/tag_matcher.rb', line 3 def self.match , patterns return true if patterns.nil? || patterns.empty? return false if .nil? || .empty? patterns.any? {|pattern| .any? {|tag| pattern_matches_string?(tag, pattern)} } end |
.pattern_matches_string?(s, pattern) ⇒ Boolean
12 13 14 |
# File 'lib/quaker/tag_matcher.rb', line 12 def self.pattern_matches_string? s, pattern s == pattern || wildcard_matches?(s, pattern) end |
.wildcard_matches?(s, pattern) ⇒ Boolean
16 17 18 19 20 21 |
# File 'lib/quaker/tag_matcher.rb', line 16 def self.wildcard_matches? s, pattern return false unless pattern.include?('*') escaped = Regexp.escape(pattern).gsub('\*','.*?') regex = Regexp.new "^#{escaped}$", Regexp::IGNORECASE !!(s =~ regex) end |