Coder Social home page Coder Social logo

zone's People

Contributors

bojanz avatar dwkitchen avatar juliend avatar lsolesen avatar pjcarly avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

zone's Issues

Provide a way to match "everything else"

RoyalMail defines several zones, with "World zone 1" defined as "anything which isn't in any of the other zones.".
The data can be seen here: http://cgit.drupalcode.org/rmzone/tree/rmzone.inc

We need a way to represent this.

We should have a ZoneMember that can take one or more zones, and returns TRUE if the referenced zone(s) don't match.

Question How to name this ZoneMember? Maybe expand the existing ZoneMemberZone to support multiple zones & a negate option?

Bug in PostalCodeHelper::buildList

If you try:
PostalCodeHelper::buildList('5:7,10:12')
you'll get something like:
[6,7,10,11,12]
and "5" will be missing because of the mix of foreach, array_merge and unset($postalCodeList[$index]) .

        $postalCodeList = explode(',', $postalCodes);
        foreach ($postalCodeList as $index => &$postalCodeItem) {
            $postalCodeItem = trim($postalCodeItem);
            if (strpos($postalCodeItem, ':') !== false) {
                $postalCodeRange = explode(':', $postalCodeItem);
                if (is_numeric($postalCodeRange[0]) && is_numeric($postalCodeRange[1])) {
                    $postalCodeRange = range($postalCodeRange[0], $postalCodeRange[1]);
                    $postalCodeList = array_merge($postalCodeList, $postalCodeRange);
                }
                unset($postalCodeList[$index]);
            }
        }

Here is my solution:

   /**
     * Builds a list of postal codes from the provided string.
     *
     * Expands any ranges into full values (e.g. "1:3" becomes "1, 2, 3").
     *
     * @param string $postalCodes The postal codes.
     *
     * @return array The list of postal codes.
     */
    protected static function buildList($postalCodes)
    {
        $resultList = [];
        $postalCodeList = explode(',', $postalCodes);
        foreach ($postalCodeList as $index => $postalCodeItem) {
            $postalCodeItem = trim($postalCodeItem);
            if (strpos($postalCodeItem, ':') !== false) {
                $postalCodeRange = explode(':', $postalCodeItem);
                if (is_numeric($postalCodeRange[0]) && is_numeric($postalCodeRange[1])) {
                    $postalCodeRange = range($postalCodeRange[0], $postalCodeRange[1]);
                    $resultList = array_merge($resultList, $postalCodeRange);
                }
                continue;
            }

            $resultList[] = $postalCodeItem;
        }

        return $resultList;
    }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.