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

Version Path
trackler-2.2.1.180 tracks/groovy/exercises/phone-number/Example.groovy
trackler-2.2.1.179 tracks/groovy/exercises/phone-number/Example.groovy
trackler-2.2.1.178 tracks/groovy/exercises/phone-number/Example.groovy
trackler-2.2.1.177 tracks/groovy/exercises/phone-number/Example.groovy
trackler-2.2.1.176 tracks/groovy/exercises/phone-number/Example.groovy
trackler-2.2.1.175 tracks/groovy/exercises/phone-number/Example.groovy
trackler-2.2.1.174 tracks/groovy/exercises/phone-number/Example.groovy
trackler-2.2.1.173 tracks/groovy/exercises/phone-number/Example.groovy
trackler-2.2.1.172 tracks/groovy/exercises/phone-number/Example.groovy
trackler-2.2.1.171 tracks/groovy/exercises/phone-number/Example.groovy
trackler-2.2.1.170 tracks/groovy/exercises/phone-number/Example.groovy
trackler-2.2.1.169 tracks/groovy/exercises/phone-number/Example.groovy
trackler-2.2.1.167 tracks/groovy/exercises/phone-number/Example.groovy
trackler-2.2.1.166 tracks/groovy/exercises/phone-number/Example.groovy
trackler-2.2.1.165 tracks/groovy/exercises/phone-number/Example.groovy
trackler-2.2.1.164 tracks/groovy/exercises/phone-number/Example.groovy
trackler-2.2.1.163 tracks/groovy/exercises/phone-number/Example.groovy
trackler-2.2.1.162 tracks/groovy/exercises/phone-number/Example.groovy
trackler-2.2.1.161 tracks/groovy/exercises/phone-number/Example.groovy
trackler-2.2.1.160 tracks/groovy/exercises/phone-number/Example.groovy