Module: AiRedactor::Patterns

Defined in:
lib/ai_redactor/patterns.rb

Constant Summary collapse

TURKISH_ID =

Turkish National ID (TC Kimlik No) - 11 digits

/\b\d{11}\b/
IBAN =

International Bank Account Number (IBAN) Supports various country formats

/\b[A-Z]{2}\d{2}[A-Z0-9]{4}\d{7}([A-Z0-9]?){0,16}\b/
CREDIT_CARD =

Credit Card Numbers (various formats)

/\b(?:\d{4}[-\s]?){3}\d{4}\b/
PHONE =

Phone Numbers (international and local formats) - more specific to avoid ID conflicts

/(?:\+\d{1,3}[-.\s])\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}|\(\d{3}\)\s?\d{3}[-.\s]?\d{4}|\b\d{3}[.\s]\d{3}[.\s]\d{4}\b/
EMAIL =

Email Addresses

/\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b/
SSN =

Social Security Numbers (US format)

/\b\d{3}-\d{2}-\d{4}\b/
IP_ADDRESS =

IP Addresses

/\b(?:\d{1,3}\.){3}\d{1,3}\b/
TAX_ID =

Tax ID Numbers (various formats)

/\b\d{2}-\d{7}\b/
ALL_PATTERNS =

All patterns combined for comprehensive scanning

{
  turkish_id: TURKISH_ID,
  iban: IBAN,
  credit_card: CREDIT_CARD,
  phone: PHONE,
  email: EMAIL,
  ssn: SSN,
  # license_plate: LICENSE_PLATE,
  ip_address: IP_ADDRESS,
  # passport: PASSPORT,
  tax_id: TAX_ID
  # bank_account: BANK_ACCOUNT
}.freeze

Class Method Summary collapse

Class Method Details

.get_pattern(name) ⇒ Object

Get pattern by name



55
56
57
# File 'lib/ai_redactor/patterns.rb', line 55

def self.get_pattern(name)
  ALL_PATTERNS[name.to_sym]
end

.pattern_namesObject

Get all pattern names



60
61
62
# File 'lib/ai_redactor/patterns.rb', line 60

def self.pattern_names
  ALL_PATTERNS.keys
end

.valid_pattern?(name) ⇒ Boolean

Check if a pattern name is valid



65
66
67
# File 'lib/ai_redactor/patterns.rb', line 65

def self.valid_pattern?(name)
  ALL_PATTERNS.key?(name.to_sym)
end