Parse and normalize street addresses
Lite::Address is an address parser and formatter. Currently supports US based addresses only.
Add this line to your application’s Gemfile:
gem 'lite-address'
And then execute:
$ bundle
Or install it yourself as:
$ gem install lite-address
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.
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
address = Lite::Address::Parser.any("1600 Pennsylvania Ave")
address.street #=> Pennsylvania
address.number #=> 1600
address.state #=> nil
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 = Lite::Address::Parser.any("1600 Pennsylvania Ave, Washington, DC, 20500")
address.to_snail #=> 1600 Pennsylvania Ave,
Washington, DC 20500
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
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.
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.
The gem is available as open source under the terms of the MIT License.
Everyone interacting in the Lite::Address project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.