Webget_ruby_person_name is a project mainly written in ..., based on the View license.
WebGet.com » Ruby » mixin methods for a person's full name, sort name, etc.
= WebGet Ruby Gem: Flexible ways to deal with real human names
Author:: Joel Parker Henderson, [email protected] Copyright:: Copyright (c) 2006-2010 Joel Parker Henderson License:: CreativeCommons License, Non-commercial Share Alike License:: LGPL, GNU Lesser General Public License
Access a human name from the fields of an ActiveRecord-based model in several combinations:
Note that the model doesn't need attributes called first_name, middle_name, and last_name to call the gem's methods; the methods are protected by testing with respond_to?(name_field).
However all of these fields which are present must be strings.
==Example class User < ActiveRecord::Base include PersonName end
u=User.first => {first_name => 'Zora', middle_name => 'Neale', last_name => 'Hurston'}
u.full_name => "Zora Neale Hurston" u.list_name => "Hurston, Zora Neale" u.first_name_middle_name => "Zora Neale" u.first_name_middle_initial_last_name => "Zora N Hurston"
==Performance Tip
Use memoize to make these very fast in Rails:
class User < ActiveRecord::Base include PersonName memoize :full_name memoize :list_name end