• Stars
    star
    115
  • Rank 305,916 (Top 7 %)
  • Language
    Ruby
  • License
    MIT License
  • Created over 15 years ago
  • Updated 11 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A Ruby gem to assist with collecting and formatting international addresses

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

More Repositories

1

freemium

Subscription management and processing (TrustCommerce, BrainTree, etc.)
Ruby
151
star
2

recordselect

Replaces <select> tags with a full-HTML, RESTful JavaScript record browser (Rails plugin)
Ruby
45
star
3

components

Rails components with inheritable views, caching, and good encapsulation.
Ruby
26
star
4

semantic-attributes

object-oriented activerecord validations and machine/human formatting
Ruby
23
star
5

mass_assignment

a better mass assignment method for ActiveRecord that allows contextual whitelists of assignable attributes
Ruby
20
star
6

nested_assignment

A proof-of-concept for adding nested mass assignment to ActiveRecord.
Ruby
20
star
7

presenting

components + scaffolding == presentations
Ruby
13
star
8

benchmarkforrails

configurable benchmarking for rails
Ruby
13
star
9

timber

Rake tasks for dealing with large rails logs, e.g. a memory-efficient task to interleave logs from multiple machines into a single chronological file. Also provides a foundation for extending custom log parsing. Does NOT require Hodel 3000.
Ruby
10
star
10

active_record_merge

Adds a merge! method to ActiveRecord, for joining records together and updating associations.
Ruby
7
star
11

photor

Photo Organizer (in Ruby)
Ruby
3
star
12

ssh-dev-env

Manages a personal workspace on EC2 with hibernation and idle timeouts.
Shell
2
star
13

HexBoard

creating a board of hex tiles in 3d, using swift and scenekit
Swift
1
star
14

dotfiles

Shell
1
star
15

simplecov-stdout

A SimpleCov formatter that prints actionable feedback directly to stdout.
Ruby
1
star
16

typeorm-relay-connection

TypeORM implementation of the Relay Connection spec
TypeScript
1
star