https://github.com/sixarm/sixarm_ruby_person_name
SixArm.com » Ruby » PersonName provides methods for names, initials, etc.
https://github.com/sixarm/sixarm_ruby_person_name
gem name person ruby
Last synced: about 2 months ago
JSON representation
SixArm.com » Ruby » PersonName provides methods for names, initials, etc.
- Host: GitHub
- URL: https://github.com/sixarm/sixarm_ruby_person_name
- Owner: SixArm
- License: other
- Created: 2010-05-25T18:26:19.000Z (almost 15 years ago)
- Default Branch: main
- Last Pushed: 2023-09-15T19:28:48.000Z (over 1 year ago)
- Last Synced: 2025-02-06T00:24:25.149Z (3 months ago)
- Topics: gem, name, person, ruby
- Language: Ruby
- Homepage: http://sixarm.com
- Size: 455 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGES.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
- Codeowners: CODEOWNERS
Awesome Lists containing this project
README
# SixArm.com → Ruby →
PersonName mixin methods for a person model[](http://badge.fury.io/rb/sixarm_ruby_person_name)
[](https://travis-ci.org/SixArm/sixarm_ruby_person_name)
[](https://codeclimate.com/github/SixArm/sixarm_ruby_person_name/maintainability)* Git:
* Doc:
* Gem:
* Contact: Joel Parker Henderson,
* Project: [changes](CHANGES.md), [license](LICENSE.md), [contributing](CONTRIBUTING.md).## Introduction
Our user models typically have accessors like these:
user.given_name => "Martin"
user.middle_name => "Luther"
user.family_name => "King"This gem is a utility to concatenate the user's name various common ways:
user.full_name => "Martin Luther King"
user.list_name => "King, Martin Luther"
user.initials => "MLK"It's fine if the model doesn't have a middle_name field, or if any of the values of any of the fields are nil or blank; this gem will do the right thing.
For docs go to
Want to help? We're happy to get pull requests.
## Install
### Gem
To install this gem in your shell or terminal:
gem install sixarm_ruby_person_name
### Gemfile
To add this gem to your Gemfile:
gem 'sixarm_ruby_person_name'
### Require
To require the gem in your code:
require 'sixarm_ruby_person_name'
## Example
Create a typical user class, include this mixin, the use it:
class User < ActiveRecord::Base
include PersonName
enduser = User.new(
given_name => 'Martin',
middle_name => 'Luther',
family_name => 'King'
)user.full_name => "Martin Luther King"
user.list_name => "King, Martin Luther"
user.initials => "MLK"
user.given_name_middle_name => "Martin Luther"
user.given_name_middle_initial => "Martin L"
user.given_name_middle_initial_family_name => "Martin L King"## Naming conventions
You can use either of these naming conventions:
* given name, middle name, family name
* first name, middle name, last name## Speed Tip
To make these very fast in Rails, you can use memoize:
class User < ActiveRecord::Base
extend ActiveSupport::Memoizable
include PersonName
memoize :full_name,
:list_name,
:initials,
:given_name_middle_name,
:given_name_middle_initial,
:given_name_middle_initial_family_name,
:given_name_family_name
end