Class: PiiScrubber::Detectors::IndianPan

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

Constant Summary collapse

PAN_REGEX =

Matches 10-character Indian Permanent Account Numbers (e.g. ABCDE1234F)

/\b[A-Za-z]{5}[0-9]{4}[A-Za-z]\b/
VALID_HOLDER_TYPES =
%w[C P H F A T B L J G].freeze

Instance Attribute Summary

Attributes inherited from Base

#name

Instance Method Summary collapse

Constructor Details

#initializeIndianPan

Returns a new instance of IndianPan.



13
14
15
# File 'lib/pii_scrubber/detectors/indian_pan.rb', line 13

def initialize
  super(name: :indian_pan)
end

Instance Method Details

#patternsObject



17
18
19
# File 'lib/pii_scrubber/detectors/indian_pan.rb', line 17

def patterns
  [PAN_REGEX]
end

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



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/pii_scrubber/detectors/indian_pan.rb', line 29

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

  pan = match.upcase
  return super if pan.length != 10

  prefix = pan[0..2]
  digits = pan[5..8]
  suffix = pan[9]
  "#{prefix}#{mask_char * 2}#{digits}#{suffix}"
end

#valid?(match) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
24
25
26
27
# File 'lib/pii_scrubber/detectors/indian_pan.rb', line 21

def valid?(match)
  pan = match.upcase
  return false unless pan.length == 10

  holder_type = pan[3]
  VALID_HOLDER_TYPES.include?(holder_type)
end