0.0
No release in over a year
Parse and normalize street addresses
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies
 Project Readme

Lite::Address

Lite::Address is an address parser and formatter. Currently supports US based addresses only.

Installation

Add this line to your application's Gemfile:

gem 'lite-address'

And then execute:

$ bundle

Or install it yourself as:

$ gem install lite-address

Table of Contents

  • Usage
  • Formatting

Usage

Parsing an address will return a Lite::Address::Format object which responds to the methods below (check the class to see more). If an address cannot be parsed then nil will be returned, but partial matches can be returned. All addresses will try to be normalized to return a predictable pattern.

Full matches

address = Lite::Address::Parser.any("1600 Pennsylvania Ave, Washington, DC, 20500")
address.street        #=> Pennsylvania
address.number        #=> 1600
address.postal_code   #=> 20500
address.city          #=> Washington
address.state         #=> DC
address.state_name    #=> District of Columbia
address.street_type   #=> Ave
address.intersection? #=> false

Partial matches

address = Lite::Address::Parser.any("1600 Pennsylvania Ave")
address.street  #=> Pennsylvania
address.number  #=> 1600
address.state   #=> nil

Formatting

A formatted can be returned to as a whole or in parts of simple strings.

address = Lite::Address::Parser.any("1600 Pennsylvania Ave, Washington, DC, 20500")
address.to_s         #=> 1600 Pennsylvania Ave, Washington, DC 20500
address.to_s(:line1) #=> 1600 Pennsylvania Ave
address.to_s(:line2) #=> Washington, DC 20500

You can also format strings to the proper country mail format.

Address only

address = Lite::Address::Parser.any("1600 Pennsylvania Ave, Washington, DC, 20500")
address.to_snail #=> 1600 Pennsylvania Ave,
                     Washington, DC 20500

Name prepended

address = Lite::Address::Parser.any("1600 Pennsylvania Ave, Washington, DC, 20500")
address.to_snail(name: 'John Doe') #=> John Doe
                                       1600 Pennsylvania Ave,
                                       Washington, DC 20500

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/drexed/lite-address. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the Lite::Address project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.