Class: PiiScrubber::Detectors::Ssn
- 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
Instance Method Summary collapse
-
#initialize ⇒ Ssn
constructor
A new instance of Ssn.
- #patterns ⇒ Object
- #replace(match, strategy: :placeholder, mask_char: "*", hmac_salt: nil) ⇒ Object
Methods inherited from Base
Constructor Details
#initialize ⇒ Ssn
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
#patterns ⇒ Object
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 |