Class: GuardrailsRuby::Checks::Topic
- Inherits:
-
GuardrailsRuby::Check
- Object
- GuardrailsRuby::Check
- GuardrailsRuby::Checks::Topic
- Defined in:
- lib/guardrails_ruby/checks/topic.rb
Instance Attribute Summary
Attributes inherited from GuardrailsRuby::Check
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 |
# File 'lib/guardrails_ruby/checks/topic.rb', line 9 def call(text, context: {}) allowed = @options.fetch(:allowed, []) return pass! if allowed.empty? # Simple keyword-based topic matching text_lower = text.downcase on_topic = allowed.any? { |topic| text_lower.include?(topic.to_s.downcase) } if on_topic pass! else fail! "Input does not match allowed topics: #{allowed.join(', ')}" end end |