Class: Uniword::Redact::Engine
- Inherits:
-
Object
- Object
- Uniword::Redact::Engine
- Defined in:
- lib/uniword/redact/engine.rb
Overview
Redaction orchestrator. Runs each pattern through the FindReplace engine and aggregates per-pattern counts.
Open/closed: adding a new pattern = PatternLibrary.register
call. Engine unchanged.
Instance Method Summary collapse
-
#initialize(document:, patterns: :pii, scope: :all) ⇒ Engine
constructor
A new instance of Engine.
- #run ⇒ Redact::Result
Constructor Details
#initialize(document:, patterns: :pii, scope: :all) ⇒ Engine
Returns a new instance of Engine.
15 16 17 18 19 |
# File 'lib/uniword/redact/engine.rb', line 15 def initialize(document:, patterns: :pii, scope: :all) @document = document @patterns = resolve_patterns(patterns) @scope = scope end |
Instance Method Details
#run ⇒ Redact::Result
22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/uniword/redact/engine.rb', line 22 def run result = Result.new return result if @patterns.empty? @patterns.each do |pattern| matcher = FindReplace::RegexMatcher.new(pattern: pattern.regex, replacement: pattern.replacement) fr = FindReplace::Engine.new(document: @document, matcher: matcher, scopes: @scope).run result.add(pattern.name, fr.count) end result end |