CARVIEW |
Every repository with this icon (

Every repository with this icon (

Run the following if you haven't already:
gem sources -a https://gems.github.com
Install the gem(s):
sudo gem install binarylogic-addresslogic
Description: | A simple ruby solution to displaying addresses. edit |
Homepage: | https://rdoc.info/projects/binarylogic/addresslogic edit |
Public Clone URL: |
git://github.com/binarylogic/addresslogic.git
Give this clone URL to anyone.
git clone git://github.com/binarylogic/addresslogic.git
|
Your Clone URL: |
Use this clone URL yourself.
git clone git@github.com:binarylogic/addresslogic.git
|
tree f89bda4a65e59511db3b5743f6a7fb46461e5461
parent ce2b50ab062e84d76ccdc690d320639d3780b38a
name | age | message | |
---|---|---|---|
![]() |
.gitignore | Thu May 14 10:29:16 -0700 2009 | Release v1.1.1 [binarylogic] |
![]() |
CHANGELOG.rdoc | Loading commit data... ![]() |
|
![]() |
LICENSE | ||
![]() |
README.rdoc | ||
![]() |
Rakefile | ||
![]() |
init.rb | Thu May 14 09:54:57 -0700 2009 | Release v1.1.0 [binarylogic] |
![]() |
lib/ | Sun Jun 28 00:35:16 -0700 2009 | Switch to jeweler from hoe [binarylogic] |
![]() |
rails/ | ||
![]() |
test/ |
Address Logic
This is a simple library that takes away the annoyances of displaying addresses in a view. Since various parts of an address can sometimes be optional, such as "street2", displaying addresses was not fun:
# some HAML view = address.street1 %br - if !address.street2.blank? = address.street2 %br == #{address.city}, #{address.state} #{address.zip} %br = address.country
That’s just ugly. Instead, you can do this with Address Logic:
= address.address_parts.join("<br />")
Or, what about a single line address?
= address.address_parts.join(", ")
Maybe you only want city and state:
= address.address_parts(:only => [:city, :state]).join(", ")
Granted the above is probably easier without using AddressLogic, but it will purge any blank items in the address, so if city or state are optional then it would be cleaner to use AddressLogic.
Install and use
As a gem:
$ sudo gem install addresslogic
Or as a plugin
$ sudo script/plugin install git://github.com/binarylogic/addresslogic.git
Then just include the AddressLogic module into any class of your choice. All that it assumes is that you have the street1, street2, city, state, zip, country (optional) methods.
class Address apply_addresslogic end
You can specify the fields too:
class Address apply_addresslogic :fields => [:street1, :street2, :city, [:state, :zip], :country] end
Helpful links
- Documentation: addresslogic.rubyforge.org
Copyright © 2009 Ben Johnson of [Binary Logic](www.binarylogic.com), released under the MIT license