Class: PiiScrubber::Detectors::Ssn

Inherits:
Base
  • Object
show all
Defined in:
lib/pii_scrubber/detectors/ssn.rb

Constant Summary collapse

SSN_REGEX =
/\b(?!000|666|9\d{2})\d{3}[ -]?(?!00)\d{2}[ -]?(?!0000)\d{4}\b/

Instance Attribute Summary

Attributes inherited from Base

#name

Instance Method Summary collapse

Methods inherited from Base

#valid?

Constructor Details

#initializeSsn

Returns a new instance of Ssn.



10
11
12
# File 'lib/pii_scrubber/detectors/ssn.rb', line 10

def initialize
  super(name: :ssn)
end

Instance Method Details

#patternsObject



14
15
16
# File 'lib/pii_scrubber/detectors/ssn.rb', line 14

def patterns
  [SSN_REGEX]
end

#replace(match, strategy: :placeholder, mask_char: "*", hmac_salt: nil) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/pii_scrubber/detectors/ssn.rb', line 18

def replace(match, strategy: :placeholder, mask_char: "*", hmac_salt: nil)
  return super unless strategy == :mask

  digits = match.scan(/\d/)
  return super if digits.size < 4

  last_four = digits.last(4).join
  "***-**-#{last_four}"
end