1. Decoder

    31 August 2009

    Decoder


    I just released Decoder.

    So what is Decoder? It is a simple library for postal code lookups. For example:


    >> country = Decoder::Countries[:US]
    => <Decoder::Country @name = "United States", @code = "US", @states = { "MA" => "Massachusetts", ... } >


    So you do a code lookup and get back a Country object. If the country has states then you can lookup via a state code:


    >> country[:MA]
    => <Decoder::State @name = "Massachusetts", @code => "MA" >


    Right now there is only state support for the United States, Canada and Australia. But adding states to a given country is as simple as adding another YAML file. If you check out the code then go to:


    $ cd lib/i18n/states/


    Create a new directory that corresponds to the country code. Then create a new YAML file called ‘eng.yml” that contains a hash of codes containing the full name for each code. The keys should be strings, not symbols.

    i18n Support


    By default Coder is set to English. If you wanted to change the language to French:


    >> Decoder.i18n = :fre


    Currently Decoder only has English support. But please feel free to add other languages. As shown above, each subdirectory under i18n currently has ‘eng.yml’ files. Just add a ‘fre.yml’ that contains the proper translations.

    Please use the 3-letter ISO 639-2 Code standard for language codes.
    http://www.loc.gov/standards/iso639-2/php/code_list.php