Class: CompletionKit::Checks::Regex

Inherits:
Object
  • Object
show all
Defined in:
app/services/completion_kit/checks/regex.rb

Instance Method Summary collapse

Instance Method Details

#call(target, config) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'app/services/completion_kit/checks/regex.rb', line 4

def call(target, config)
  options = 0
  options |= Regexp::IGNORECASE if config["case_sensitive"] == false
  options |= Regexp::MULTILINE if config["multiline"] == true
  pattern = Regexp.new(config["pattern"].to_s, options)

  if pattern.match?(target.to_s)
    Result.new(passed: true, detail: "matched /#{config["pattern"]}/")
  else
    Result.new(passed: false, detail: "no match for /#{config["pattern"]}/")
  end
rescue RegexpError => e
  Result.new(passed: false, detail: "invalid pattern: #{e.message}")
end