Class: Uniword::Redact::Engine

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(document:, patterns: :pii, scope: :all) ⇒ Engine

Returns a new instance of Engine.

Parameters:

  • document (Wordprocessingml::DocumentRoot)
  • patterns (Array<Pattern>, :pii) (defaults to: :pii)

    patterns to apply (:pii selects the default library)

  • scope (Symbol, Array<Symbol>, :all) (defaults to: :all)

    find-replace scope



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

#runRedact::Result

Returns:



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