Class: PiiScrubber::Detectors::Phone
- 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
Instance Method Summary collapse
-
#initialize ⇒ Phone
constructor
A new instance of Phone.
- #patterns ⇒ Object
- #valid?(match) ⇒ Boolean
Methods inherited from Base
Constructor Details
#initialize ⇒ Phone
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
#patterns ⇒ Object
15 16 17 |
# File 'lib/pii_scrubber/detectors/phone.rb', line 15 def patterns [PHONE_REGEX] end |
#valid?(match) ⇒ 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 |