Coder Social home page Coder Social logo

dbaq / snail Goto Github PK

View Code? Open in Web Editor NEW

This project forked from cainlevy/snail

0.0 2.0 1.0 232 KB

a Ruby on Rails plugin to assist with collecting and formatting international addresses

Home Page: http://codelevy.com

License: MIT License

Ruby 100.00%

snail's Introduction

Snail

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

Problems

The first problem when sending mail is getting it OUT of the originating country. This means writing the destination country in a manner that the originating country understands.

The second problem is getting it TO the correct address. This means writing the address lines in a manner that the destination country understands.

Solutions

Snail relies on practical formatting guidelines gathered by Frank's Compulsive Guide to Postal Addresses, plus internationalized country names from The Unicode CLDR Project.

Getting Started

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 => "AU"
).to_s

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

By default addresses with a country of USA are considered domestic and the country will be left off any output. To change the home country:

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

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

You can override this default behavior by specifying with_country as true or false:

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

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

See the test cases for more.

Fun Times

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.

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).

Copyright (c) 2009-2016 Lance Ivy, released under the MIT license

snail's People

Contributors

bousquet avatar cainlevy avatar dlepage avatar joshuapinter avatar tiegz avatar tinynumbers avatar yob avatar

Watchers

 avatar  avatar

Forkers

myerp

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.