Socket
Book a DemoInstallSign in
Socket

addresslogic_rails

Package Overview
Dependencies
Maintainers
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

addresslogic_rails

1.0.0
bundlerRubygems
Version published
Maintainers
2
Created
Source

Build Status

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:

Example ERB use

<%= address.street1 %>
<% if !address.street2.blank? %> <%= address.street2 %> <% end %>
<%= "#{address.city}, #{address.state} #{address.zip}" %>
<%= address.country %>

That's just ugly. Instead, you can do this with Address Logic:

<%= address.address_parts.join("
") %>

Example HAML use

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("
")

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.

Build Notes

This should compile and build on Ruby 1.8.7/ree, MRI 1.9.x, JRuby and Rubunius, but is only officially supported under MRI 1.9.3

Install and use

Install from rubygems

$ sudo gem install addresslogic_rails

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

  •   <b>Better Documentation:</b> (Coming soon)
    
  •   Copyright (c) 2009 Ben Johnson of [Binary Logic](http://www.binarylogic.com), released under the MIT license
    
  •   This release (c) 2011 Mike Simkins of [G7OBS Software](http://software.g7obs.com), released under the MIT license
    

FAQs

Package last updated on 18 Jul 2012

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.