Class: Webhookdb::PhoneNumber::US
- Inherits:
-
Object
- Object
- Webhookdb::PhoneNumber::US
- Defined in:
- lib/webhookdb/phone_number.rb
Constant Summary collapse
- REGEXP =
/^1[0-9]{10}$/
Class Method Summary collapse
Class Method Details
.format(s) ⇒ Object
22 23 24 25 |
# File 'lib/webhookdb/phone_number.rb', line 22 def self.format(s) raise ArgumentError, "#{s} must be a normalized to #{REGEXP}" unless self.valid_normalized?(s) return "(#{s[1..3]}) #{s[4..6]}-#{s[7..]}" end |
.normalize(s) ⇒ Object
7 8 9 10 11 |
# File 'lib/webhookdb/phone_number.rb', line 7 def self.normalize(s) norm = Phony.normalize(s, cc: "1") norm = "1#{norm}" if norm.length == 10 && norm.first == "1" return norm end |
.valid?(s) ⇒ Boolean
13 14 15 16 |
# File 'lib/webhookdb/phone_number.rb', line 13 def self.valid?(s) return false if s.nil? return self.valid_normalized?(self.normalize(s)) end |
.valid_normalized?(s) ⇒ Boolean
18 19 20 |
# File 'lib/webhookdb/phone_number.rb', line 18 def self.valid_normalized?(s) return REGEXP.match?(s) end |