Sha256: de8323c10e50ca15f957f48de413dd2c0b7c6dcf81899c07aed408d4952606c9
Contents?: true
Size: 577 Bytes
Versions: 71
Compression:
Stored size: 577 Bytes
Contents
class PhoneNumber { private static NANP_PATTERN = ~/^(?:\+?1)?[-.(\s]*([2-9]\d\d)[-.)\s]*\s?([2-9]\d\d)[-.\s]*(\d{4})\s*$/ final String areaCode, exchange, subscriber, number, prettyNumber PhoneNumber(String input) { def matcher = (input =~ NANP_PATTERN) def groups = matcher ? matcher[0].tail() : ['000', '000', '0000'] (areaCode, exchange, subscriber) = groups number = "${areaCode}${exchange}${subscriber}" prettyNumber = "(${areaCode}) ${exchange}-${subscriber}" } String toString() { prettyNumber } }
Version data entries
71 entries across 71 versions & 1 rubygems