Class: Company::Phone

Inherits:
Object
  • Object
show all
Defined in:
lib/company/phone.rb

Overview

The ten digits a North American number is, whatever punctuation it arrived wearing.

Constant Summary collapse

NANP =

Ten digits whose area code and exchange open with 2 through 9.

/\A[2-9]\d{2}[2-9]\d{6}\z/

Class Method Summary collapse

Class Method Details

.from(number) ⇒ String?

Returns ten digits to dial, or nil where none is held or none can be dialed.

Parameters:

  • number (String, nil) —

    number as the platform holds it.

Returns:

  • (String, nil) —

    ten digits to dial, or nil where none is held or none can be dialed.



9
10
11
12
# File 'lib/company/phone.rb', line 9

def self.from(number)
  digits = number.to_s.delete('^0-9').delete_prefix '1'
  digits if NANP.match? digits
end