Class: PiiScrubber::Detectors::Phone

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

Constant Summary collapse

PHONE_REGEX =

Matches international and common domestic phone number formats

/(?:\+|\b)(?:[0-9]{1,3}[ -]?)?\(?[0-9]{3}\)?[ -]?[0-9]{3}[ -]?[0-9]{4}\b/

Instance Attribute Summary

Attributes inherited from Base

#name

Instance Method Summary collapse

Methods inherited from Base

#replace

Constructor Details

#initializePhone

Returns a new instance of Phone.



11
12
13
# File 'lib/pii_scrubber/detectors/phone.rb', line 11

def initialize
  super(name: :phone)
end

Instance Method Details

#patternsObject



15
16
17
# File 'lib/pii_scrubber/detectors/phone.rb', line 15

def patterns
  [PHONE_REGEX]
end

#valid?(match) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
22
23
# File 'lib/pii_scrubber/detectors/phone.rb', line 19

def valid?(match)
  # Ensure it has between 10 and 15 digits
  digits = match.gsub(/\D/, "")
  digits.length >= 10 && digits.length <= 15
end