Class: PromptScrub::Redactor

Inherits:
Object
  • Object
show all
Defined in:
lib/promptscrub/redactor.rb

Instance Method Summary collapse

Constructor Details

#initialize(vault, detectors) ⇒ Redactor

Returns a new instance of Redactor.



5
6
7
8
# File 'lib/promptscrub/redactor.rb', line 5

def initialize(vault, detectors)
  @vault     = vault
  @detectors = detectors
end

Instance Method Details

#scrub(text) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/promptscrub/redactor.rb', line 10

def scrub(text)
  return text if text.nil? || text.empty?

  result = text.dup
  @detectors.each do |detector|
    detector.scan(result).each do |match|
      token  = @vault.tokenize(detector.type, match)
      result = result.gsub(match, token)
    end
  end
  result
end