Class: PiiScrubber::Detectors::Base
- Inherits:
-
Object
- Object
- PiiScrubber::Detectors::Base
- Defined in:
- lib/pii_scrubber/detectors/base.rb
Direct Known Subclasses
ApiKey, CanadianSin, CreditCard, DatabaseUrl, Email, Iban, IndianAadhaar, IndianPan, IpAddress, Phone, Ssn, UkNino
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#initialize(name:) ⇒ Base
constructor
A new instance of Base.
-
#patterns ⇒ Object
Returns array of Regexp objects for matching.
-
#replace(match, strategy: :placeholder, mask_char: "*", hmac_salt: nil) ⇒ Object
Generates replacement text for the match based on strategy.
-
#valid?(_match) ⇒ Boolean
Validates if the regex match is genuinely a PII instance (prevents false positives).
Constructor Details
#initialize(name:) ⇒ Base
Returns a new instance of Base.
10 11 12 |
# File 'lib/pii_scrubber/detectors/base.rb', line 10 def initialize(name:) @name = name.to_sym end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'lib/pii_scrubber/detectors/base.rb', line 8 def name @name end |
Instance Method Details
#patterns ⇒ Object
Returns array of Regexp objects for matching
15 16 17 |
# File 'lib/pii_scrubber/detectors/base.rb', line 15 def patterns [] end |
#replace(match, strategy: :placeholder, mask_char: "*", hmac_salt: nil) ⇒ Object
Generates replacement text for the match based on strategy
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/pii_scrubber/detectors/base.rb', line 25 def replace(match, strategy: :placeholder, mask_char: "*", hmac_salt: nil) if strategy.is_a?(Proc) return strategy.call(match, name) end case strategy when :placeholder "[REDACTED:#{name.to_s.upcase}]" when :mask mask_value(match, mask_char: mask_char) when :hash digest = hmac_salt ? Digest::SHA256.hexdigest("#{hmac_salt}:#{match}")[0..7] : Digest::SHA256.hexdigest(match)[0..7] "[ANON:#{digest}]" else "[REDACTED:#{name.to_s.upcase}]" end end |
#valid?(_match) ⇒ Boolean
Validates if the regex match is genuinely a PII instance (prevents false positives)
20 21 22 |
# File 'lib/pii_scrubber/detectors/base.rb', line 20 def valid?(_match) true end |