Class: TellIo::Countries::Usa

Inherits:
Country
  • Object
show all
Defined in:
lib/countries/usa.rb

Class Method Summary collapse

Class Method Details

.format(phone) ⇒ Object



11
12
13
# File 'lib/countries/usa.rb', line 11

def self.format(phone)
  phone.gsub(/\A\+1(\d{3})(\d{3})(\d{4})\z/, "(\\1) \\2-\\3")
end

.generateObject



15
16
17
# File 'lib/countries/usa.rb', line 15

def self.generate
  "+1#{rand(200..999)}#{rand(100..999)}#{rand(1000..9999)}"
end

.valid?(phone) ⇒ Boolean

Returns:

  • (Boolean)


7
8
9
# File 'lib/countries/usa.rb', line 7

def self.valid?(phone)
  !!(phone =~ /\A\+1\d{10}\z/)
end