Class: WildcardMatcher

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/wildcard_matcher.rb

Class Method Summary collapse

Class Method Details

.match?(wildcard_string, candidate_string) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
13
14
15
16
17
18
# File 'lib/wildcard_matcher.rb', line 10

def self.match?(wildcard_string, candidate_string)
  return false unless wildcard_string && candidate_string

  regex_string = "a#{wildcard_string.downcase}a".split("*")
                                                .map { |p| Regexp.quote(p) }
                                                .join(".*").gsub(/^a|a$/, "")
  regex = /^#{regex_string}$/
  regex.match?(candidate_string.downcase)
end