International Postal Address Formatting

International postal address formatting with HTML Microformats.

Build Status

Installation

Add this line to your application's Gemfile:

gem 'postal_address'

And then execute:

$ bundle

Or install it yourself as:

$ gem install postal_address

Usage

address = {
  recipient: 'Tobias Füncke', 
  street: '101 Broadway', 
  city: 'New York City', 
  zip: '10002', 
  state: 'NY', 
  country_code: 'us'
}

Postal::Address.new(address).to_s

Tobias F

Set a home country (country names are not display for those addresses)

Postal.home_country = 'us'

p = Postal::Address.new(address)
p.to_html(tag: 'section', itemprop: 'address')

<section itemprop="address" itemscope itemtype="http://schema.org/PostalAddress">
  <span itemprop="name">Tobias F

Standalone AddressFormatter usage:

Postal::AddressFormatter::Text.new(address).render

Postal::AddressFormatter::HTML.new(address).render(tag: 'section', itemprop: 'address')

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request