public
Description: a Ruby on Rails plugin to assist with collecting and formatting international addresses
Homepage: http://codelevy.com
Clone URL: git://github.com/cainlevy/snail.git
dlepage (author)
Mon Nov 23 12:22:26 -0800 2009
cainlevy (committer)
Mon Nov 23 16:01:19 -0800 2009
snail /
name age message
file MIT-LICENSE Thu Jul 02 16:08:11 -0700 2009 declaration of intent: this will be a plugin [cainlevy]
file README.rdoc Wed Jul 15 16:52:49 -0700 2009 readme tweaks [cainlevy]
file Rakefile Thu Jul 02 16:08:11 -0700 2009 declaration of intent: this will be a plugin [cainlevy]
file init.rb Wed Jul 15 16:52:57 -0700 2009 mix the helpers into actionview [cainlevy]
directory lib/ Mon Nov 23 12:22:26 -0800 2009 Add more countries. [dlepage]
directory test/ Thu Jul 16 11:10:18 -0700 2009 with unknown countries, log a message and use d... [cainlevy]
README.rdoc

Snail

International snail mail addressing is a pain. This plugin begins to make it easier.

How?

The basic idea is that mailing addresses need first and foremost to make it OUT of the originating country. It’s beyond the scope of my current work to consider any originating country besides the United States, so that’s where I am beginning. I will leave other countries of origination to the open source community.

Given the United States as a point of origin, my effort here is based on Frank’s Compulsive Guide to Postal Addresses, available from www.columbia.edu/kermit/postal.html as of July 2009, and the USPS International Mail Manual (IMM), available from pe.usps.gov/text/imm/immidx.htm.

The United States Postal Service (USPS) requires (strongly prefers?) a few things:

  • That the address be 5 lines long or less.
  • That the last address line be a country name recognized by the USPS, in all uppercase.
  • That the city line (comprising the city, state, and postal code as appropriate) immediately precede the country line.

The rest of the address should be formatted according to the rules of the receiving country.

Nearly all of the variation in formatting rules applies to the city line. Depending on the receiving country, the three component pieces (e.g. city, state, postal code) have different names, are pieced together in different order with different punctuation, and may or may not be required.

And then there’s Great Britain, which Frank’s Compulsive Guide describes as "where to find the most confusing addresses on earth" (a description confirmed and further confused by a source from within Royal Mail).

The Future

I hope to tackle this plugin in stages, with help from the open source community:

# provide standardized USPS country names # provide basic formatting rules for the city line in major countries # provide basic country-specific validation logic # build a best-practice form field generator to collect appropriate address information # expand to other originating countries # continue fleshing out the formatting and validation

Example

Taking regular data and formatting it into an internationally mailable address:

  Snail.new(
    :name => "Jon Doe",
    :line_1 => "12345 Somewhere Ln",
    :line_2 => nil,
    :city => "Bentley",
    :region => "WA",
    :postal_code => "6102",
    :country => "Australia"
  ).to_address

  => "Jon Doe\n12345 Somewhere Ln\nBENTLEY WA  6102\nAUSTRALIA"

See the test cases for more.

Copyright © 2009 Lance Ivy, released under the MIT license