Class: GuardrailsRuby::Checks::CompetitorMention

Inherits:
GuardrailsRuby::Check show all
Defined in:
lib/guardrails_ruby/checks/competitor_mention.rb

Instance Attribute Summary

Attributes inherited from GuardrailsRuby::Check

#options

Instance Method Summary collapse

Methods inherited from GuardrailsRuby::Check

check_name, direction, #initialize, lookup

Constructor Details

This class inherits a constructor from GuardrailsRuby::Check

Instance Method Details

#call(text, context: {}) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/guardrails_ruby/checks/competitor_mention.rb', line 9

def call(text, context: {})
  names = @options.fetch(:names, [])
  return pass! if names.empty?

  found = names.select { |name| text.downcase.include?(name.downcase) }

  if found.any?
    sanitized = redact_competitors(text, found)
    fail! "Competitor mention detected: #{found.join(', ')}",
      matches: found,
      sanitized: sanitized
  else
    pass!
  end
end