Giter Club home page Giter Club logo

addresslogic's Introduction

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

Install from rubyforge

$ sudo gem install addresslogic

Install from github:

$ sudo gem install binarylogic-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

* Documentation: rdoc.info/projects/binarylogic/addresslogic

Copyright © 2009 Ben Johnson of [Binary Logic](www.binarylogic.com), released under the MIT license

addresslogic's People

Contributors

binarylogic avatar mooktakim avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.