sixarm_ruby_person_name 1.0.4 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +129 -0
- data/lib/sixarm_ruby_person_name.rb +1 -1
- data/test/sixarm_ruby_person_name_test.rb +180 -88
- data.tar.gz.sig +0 -0
- metadata +43 -33
- metadata.gz.sig +0 -0
- data/CHANGELOG.txt +0 -4
- data/INSTALL.txt +0 -32
- data/LICENSE.txt +0 -25
- data/README.rdoc +0 -52
data/README.md
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
# SixArm.com » Ruby » <br> PersonName gem accesses a person's name from ActiveRecord fields
|
2
|
+
|
3
|
+
* Docs: <http://sixarm.com/sixarm_ruby_person_name/doc>
|
4
|
+
* Repo: <http://github.com/sixarm/sixarm_ruby_person_name>
|
5
|
+
* Email: Joel Parker Henderson, <joel@sixarm.com>
|
6
|
+
|
7
|
+
|
8
|
+
## Introduction
|
9
|
+
|
10
|
+
Our user models typically have accessors like these:
|
11
|
+
|
12
|
+
user.first_name => "Martin"
|
13
|
+
user.middle_name => "Luther"
|
14
|
+
user.last_name => "King"
|
15
|
+
|
16
|
+
This gem is a utility to concatenate the user's name various common ways:
|
17
|
+
|
18
|
+
user.full_name => "Martin Luther King"
|
19
|
+
user.list_name => "King, Martin Luther"
|
20
|
+
user.initials => "MLK"
|
21
|
+
|
22
|
+
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.
|
23
|
+
|
24
|
+
For docs go to <http://sixarm.com/sixarm_ruby_person_name/doc>
|
25
|
+
|
26
|
+
Want to help? We're happy to get pull requests.
|
27
|
+
|
28
|
+
|
29
|
+
## Install quickstart
|
30
|
+
|
31
|
+
Install:
|
32
|
+
|
33
|
+
gem install sixarm_ruby_person_name
|
34
|
+
|
35
|
+
Bundler:
|
36
|
+
|
37
|
+
gem "sixarm_ruby_person_name", "~>1.0.4"
|
38
|
+
|
39
|
+
Require:
|
40
|
+
|
41
|
+
require "sixarm_ruby_person_name"
|
42
|
+
|
43
|
+
|
44
|
+
## Install with security (optional)
|
45
|
+
|
46
|
+
To enable high security for all our gems:
|
47
|
+
|
48
|
+
wget http://sixarm.com/sixarm.pem
|
49
|
+
gem cert --add sixarm.pem
|
50
|
+
gem sources --add http://sixarm.com
|
51
|
+
|
52
|
+
To install with high security:
|
53
|
+
|
54
|
+
gem install sixarm_ruby_person_name --test --trust-policy HighSecurity
|
55
|
+
|
56
|
+
|
57
|
+
## Example
|
58
|
+
|
59
|
+
Create a typical user class, include this mixin, the use it:
|
60
|
+
|
61
|
+
require "sixarm_ruby_person_name"
|
62
|
+
|
63
|
+
class User < ActiveRecord::Base
|
64
|
+
include PersonName
|
65
|
+
end
|
66
|
+
|
67
|
+
user=User.new(
|
68
|
+
first_name => 'Martin',
|
69
|
+
middle_name => 'Luther',
|
70
|
+
last_name => 'King'
|
71
|
+
)
|
72
|
+
|
73
|
+
user.full_name => "Martin Luther King"
|
74
|
+
user.list_name => "King, Martin Luther"
|
75
|
+
user.initials => "MLK"
|
76
|
+
user.first_name_middle_name => "Martin Luther"
|
77
|
+
user.first_name_middle_initial => "Martin L"
|
78
|
+
user.first_name_middle_initial_last_name => "Martin L King"
|
79
|
+
|
80
|
+
|
81
|
+
## Performance Tip
|
82
|
+
|
83
|
+
To make these very fast in Rails, you can use memoize:
|
84
|
+
|
85
|
+
class User < ActiveRecord::Base
|
86
|
+
extend ActiveSupport::Memoizable
|
87
|
+
include PersonName
|
88
|
+
memoize :full_name,
|
89
|
+
:list_name,
|
90
|
+
:initials,
|
91
|
+
:first_name_middle_name,
|
92
|
+
:first_name_middle_initial,
|
93
|
+
:first_name_middle_initial_last_name,
|
94
|
+
:first_name_last_name
|
95
|
+
end
|
96
|
+
|
97
|
+
|
98
|
+
## Changes
|
99
|
+
|
100
|
+
* 2012-03-14 1.0.4 Update docs, tests
|
101
|
+
* 2012-01-24 1.0.4 Add #initals method. Add CHANGELOG.txt file. Update examples.
|
102
|
+
|
103
|
+
## License
|
104
|
+
|
105
|
+
You may choose any of these open source licenses:
|
106
|
+
|
107
|
+
* Apache License
|
108
|
+
* BSD License
|
109
|
+
* CreativeCommons License, Non-commercial Share Alike
|
110
|
+
* GNU General Public License Version 2 (GPL 2)
|
111
|
+
* GNU Lesser General Public License (LGPL)
|
112
|
+
* MIT License
|
113
|
+
* Perl Artistic License
|
114
|
+
* Ruby License
|
115
|
+
|
116
|
+
The software is provided "as is", without warranty of any kind,
|
117
|
+
express or implied, including but not limited to the warranties of
|
118
|
+
merchantability, fitness for a particular purpose and noninfringement.
|
119
|
+
|
120
|
+
In no event shall the authors or copyright holders be liable for any
|
121
|
+
claim, damages or other liability, whether in an action of contract,
|
122
|
+
tort or otherwise, arising from, out of or in connection with the
|
123
|
+
software or the use or other dealings in the software.
|
124
|
+
|
125
|
+
This license is for the included software that is created by SixArm;
|
126
|
+
some of the included software may have its own licenses, copyrights,
|
127
|
+
authors, etc. and these do take precedence over the SixArm license.
|
128
|
+
|
129
|
+
Copyright (c) 2005-2013 Joel Parker Henderson
|
@@ -1,122 +1,214 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
|
-
require '
|
2
|
+
require 'minitest/autorun'
|
3
3
|
require 'simplecov'
|
4
4
|
SimpleCov.start
|
5
5
|
require 'sixarm_ruby_person_name'
|
6
6
|
|
7
|
-
|
7
|
+
describe PersonName do
|
8
8
|
|
9
|
-
|
10
|
-
assert_equal("abc def",p("abc","def","ghi").first_name_middle_name)
|
11
|
-
assert_equal("abc" ,p("abc",nil ,"ghi").first_name_middle_name)
|
12
|
-
assert_equal("def" ,p(nil ,"def" ,"ghi").first_name_middle_name)
|
13
|
-
assert_equal("" ,p(nil ,nil ,"ghi").first_name_middle_name)
|
14
|
-
end
|
9
|
+
include PersonName
|
15
10
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
11
|
+
before do
|
12
|
+
F ||= Person.new("abc", nil, nil) # First name
|
13
|
+
M ||= Person.new( nil, "def", nil) # Middle name
|
14
|
+
L ||= Person.new( nil, nil, "ghi") # Last name
|
15
|
+
FM ||= Person.new("abc", "def", nil) # First name & Middle name
|
16
|
+
FL ||= Person.new("abc", nil, "ghi") # First name & Last name
|
17
|
+
ML ||= Person.new( nil, "def", "ghi") # Middle name & Last name
|
18
|
+
FML ||= Person.new("abc", "def", "ghi") # First name & Middle name & Last name
|
19
|
+
end
|
22
20
|
|
23
|
-
|
24
|
-
assert_equal("abc",p("abc",nil,nil).first_name_middle_initial_last_name)
|
25
|
-
end
|
21
|
+
describe "#first_name_middle_name" do
|
26
22
|
|
27
|
-
|
28
|
-
|
29
|
-
|
23
|
+
it "with first" do
|
24
|
+
F.first_name_middle_name.must_equal("abc")
|
25
|
+
end
|
30
26
|
|
31
|
-
|
32
|
-
|
33
|
-
|
27
|
+
it "with middle" do
|
28
|
+
M.first_name_middle_name.must_equal("def")
|
29
|
+
end
|
34
30
|
|
35
|
-
|
36
|
-
|
37
|
-
|
31
|
+
it "with last" do
|
32
|
+
L.first_name_middle_name.must_equal("")
|
33
|
+
end
|
34
|
+
|
35
|
+
it "with first & middle" do
|
36
|
+
FM.first_name_middle_name.must_equal("abc def")
|
37
|
+
end
|
38
38
|
|
39
|
-
|
40
|
-
|
41
|
-
|
39
|
+
it "with first & last" do
|
40
|
+
FL.first_name_middle_name.must_equal("abc")
|
41
|
+
end
|
42
42
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
end
|
43
|
+
it "with middle & last" do
|
44
|
+
ML.first_name_middle_name.must_equal("def")
|
45
|
+
end
|
47
46
|
|
48
|
-
|
49
|
-
|
50
|
-
|
47
|
+
it "with first & middle & last" do
|
48
|
+
FML.first_name_middle_name.must_equal("abc def")
|
49
|
+
end
|
51
50
|
|
52
|
-
|
53
|
-
assert_equal("def",p(nil,"def",nil).full_name)
|
54
|
-
end
|
51
|
+
end
|
55
52
|
|
56
|
-
|
57
|
-
assert_equal("ghi",p(nil,nil,"ghi").full_name)
|
58
|
-
end
|
53
|
+
describe "#first_name_middle_initial" do
|
59
54
|
|
60
|
-
|
61
|
-
|
62
|
-
|
55
|
+
it "with first" do
|
56
|
+
F.first_name_middle_initial.must_equal("abc")
|
57
|
+
end
|
63
58
|
|
64
|
-
|
65
|
-
|
66
|
-
|
59
|
+
it "with middle" do
|
60
|
+
M.first_name_middle_initial.must_equal("d")
|
61
|
+
end
|
67
62
|
|
68
|
-
|
69
|
-
|
70
|
-
|
63
|
+
it "with last" do
|
64
|
+
L.first_name_middle_initial.must_equal("")
|
65
|
+
end
|
71
66
|
|
72
|
-
|
73
|
-
|
74
|
-
|
67
|
+
it "with first & middle" do
|
68
|
+
FM.first_name_middle_initial.must_equal("abc d")
|
69
|
+
end
|
75
70
|
|
76
|
-
|
77
|
-
|
78
|
-
|
71
|
+
it "with first & last" do
|
72
|
+
FL.first_name_middle_initial.must_equal("abc")
|
73
|
+
end
|
79
74
|
|
80
|
-
|
81
|
-
|
82
|
-
|
75
|
+
it "with middle & last" do
|
76
|
+
ML.first_name_middle_initial.must_equal("d")
|
77
|
+
end
|
83
78
|
|
84
|
-
|
85
|
-
|
86
|
-
|
79
|
+
it "with first & middle & last" do
|
80
|
+
FML.first_name_middle_initial.must_equal("abc d")
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
describe "#first_name_middle_initial_last_name" do
|
87
86
|
|
88
|
-
|
89
|
-
|
90
|
-
|
87
|
+
it "with first" do
|
88
|
+
F.first_name_middle_initial_last_name.must_equal("abc")
|
89
|
+
end
|
91
90
|
|
92
|
-
|
93
|
-
|
94
|
-
|
91
|
+
it "with middle" do
|
92
|
+
M.first_name_middle_initial_last_name.must_equal("d")
|
93
|
+
end
|
95
94
|
|
96
|
-
|
97
|
-
|
98
|
-
|
95
|
+
it "with last" do
|
96
|
+
L.first_name_middle_initial_last_name.must_equal("ghi")
|
97
|
+
end
|
99
98
|
|
100
|
-
|
101
|
-
|
102
|
-
|
99
|
+
it "with first &_middle" do
|
100
|
+
FM.first_name_middle_initial_last_name.must_equal("abc d")
|
101
|
+
end
|
103
102
|
|
104
|
-
|
105
|
-
|
106
|
-
|
103
|
+
it "with first &_last" do
|
104
|
+
FL.first_name_middle_initial_last_name.must_equal("abc ghi")
|
105
|
+
end
|
107
106
|
|
108
|
-
|
109
|
-
|
110
|
-
|
107
|
+
it "with middle &_last" do
|
108
|
+
ML.first_name_middle_initial_last_name.must_equal("d ghi")
|
109
|
+
end
|
111
110
|
|
112
|
-
|
113
|
-
|
114
|
-
|
111
|
+
it "with first & middle &_last" do
|
112
|
+
FML.first_name_middle_initial_last_name.must_equal("abc d ghi")
|
113
|
+
end
|
115
114
|
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
115
|
+
end
|
116
|
+
|
117
|
+
describe "#full_name" do
|
118
|
+
|
119
|
+
it "with first" do
|
120
|
+
F.full_name.must_equal("abc")
|
121
|
+
end
|
122
|
+
|
123
|
+
it "with middle" do
|
124
|
+
M.full_name.must_equal("def")
|
125
|
+
end
|
126
|
+
|
127
|
+
it "with last" do
|
128
|
+
L.full_name.must_equal("ghi")
|
129
|
+
end
|
130
|
+
|
131
|
+
it "with first & middle" do
|
132
|
+
FM.full_name.must_equal("abc def")
|
133
|
+
end
|
134
|
+
|
135
|
+
it "with first & last" do
|
136
|
+
FL.full_name.must_equal("abc ghi")
|
137
|
+
end
|
138
|
+
|
139
|
+
it "with middle & last" do
|
140
|
+
ML.full_name.must_equal("def ghi")
|
141
|
+
end
|
142
|
+
|
143
|
+
it "with first & middle & last" do
|
144
|
+
FML.full_name.must_equal("abc def ghi")
|
145
|
+
end
|
146
|
+
|
147
|
+
end
|
148
|
+
|
149
|
+
describe "#list_name" do
|
150
|
+
|
151
|
+
it "with first" do
|
152
|
+
F.list_name.must_equal("abc")
|
153
|
+
end
|
154
|
+
|
155
|
+
it "with middle" do
|
156
|
+
M.list_name.must_equal("def")
|
157
|
+
end
|
158
|
+
|
159
|
+
it "with last" do
|
160
|
+
L.list_name.must_equal("ghi")
|
161
|
+
end
|
162
|
+
|
163
|
+
it "with first & middle" do
|
164
|
+
FM.list_name.must_equal("abc def")
|
165
|
+
end
|
166
|
+
|
167
|
+
it "with first & last" do
|
168
|
+
FL.list_name.must_equal("ghi, abc")
|
169
|
+
end
|
170
|
+
|
171
|
+
it "with middle & last" do
|
172
|
+
ML.list_name.must_equal("ghi, def")
|
173
|
+
end
|
174
|
+
|
175
|
+
it "with first & middle & last" do
|
176
|
+
FML.list_name.must_equal("ghi, abc def")
|
177
|
+
end
|
178
|
+
|
179
|
+
end
|
180
|
+
|
181
|
+
describe "#initials" do
|
182
|
+
|
183
|
+
it "with first" do
|
184
|
+
F.initials.must_equal("a")
|
185
|
+
end
|
186
|
+
|
187
|
+
it "with middle" do
|
188
|
+
M.initials.must_equal("d")
|
189
|
+
end
|
190
|
+
|
191
|
+
it "with last" do
|
192
|
+
L.initials.must_equal("g")
|
193
|
+
end
|
194
|
+
|
195
|
+
it "with first & middle" do
|
196
|
+
FM.initials.must_equal("ad")
|
197
|
+
end
|
198
|
+
|
199
|
+
it "with first & last" do
|
200
|
+
FL.initials.must_equal("ag")
|
201
|
+
end
|
202
|
+
|
203
|
+
it "with middle & last" do
|
204
|
+
ML.initials.must_equal("dg")
|
205
|
+
end
|
206
|
+
|
207
|
+
it "with first & middle & last" do
|
208
|
+
FML.initials.must_equal("adg")
|
209
|
+
end
|
210
|
+
|
211
|
+
end
|
120
212
|
|
121
213
|
end
|
122
214
|
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sixarm_ruby_person_name
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,33 +9,46 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain:
|
12
|
-
- !
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
12
|
+
- ! '-----BEGIN CERTIFICATE-----
|
13
|
+
|
14
|
+
MIIDBDCCAm2gAwIBAgIJAKPwEETU5bHoMA0GCSqGSIb3DQEBBQUAMGAxCzAJBgNV
|
15
|
+
|
16
|
+
BAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlhMRYwFAYDVQQHEw1TYW4gRnJhbmNp
|
17
|
+
|
18
|
+
c2NvMQ8wDQYDVQQKEwZTaXhBcm0xEzARBgNVBAMTCnNpeGFybS5jb20wHhcNMTAx
|
19
|
+
|
20
|
+
MjEzMjMyNzEzWhcNMTMwOTA4MjMyNzEzWjBgMQswCQYDVQQGEwJVUzETMBEGA1UE
|
21
|
+
|
22
|
+
CBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNU2FuIEZyYW5jaXNjbzEPMA0GA1UEChMG
|
23
|
+
|
24
|
+
U2l4QXJtMRMwEQYDVQQDEwpzaXhhcm0uY29tMIGfMA0GCSqGSIb3DQEBAQUAA4GN
|
25
|
+
|
26
|
+
ADCBiQKBgQC94mD9JDwBsunsOI0VR3CXXbOWg9cWaWciwFyJNFiM7A9I8KPLfXUw
|
27
|
+
|
28
|
+
QC4czUe5ZuG4WHvinrWhkrCK+1dWBqoEClxdF/FoKO5a+tonGCjjmfy81JmFjjyx
|
29
|
+
|
30
|
+
eTsjsHyvw+Qik9kpf9aj6+pnkNrVswgNHVea2o9yabbEiS6VSeJWoQIDAQABo4HF
|
31
|
+
|
32
|
+
MIHCMB0GA1UdDgQWBBQzPJtqmSgc53eDN7aSzDQwr9TALDCBkgYDVR0jBIGKMIGH
|
33
|
+
|
34
|
+
gBQzPJtqmSgc53eDN7aSzDQwr9TALKFkpGIwYDELMAkGA1UEBhMCVVMxEzARBgNV
|
35
|
+
|
36
|
+
BAgTCkNhbGlmb3JuaWExFjAUBgNVBAcTDVNhbiBGcmFuY2lzY28xDzANBgNVBAoT
|
37
|
+
|
38
|
+
BlNpeEFybTETMBEGA1UEAxMKc2l4YXJtLmNvbYIJAKPwEETU5bHoMAwGA1UdEwQF
|
39
|
+
|
40
|
+
MAMBAf8wDQYJKoZIhvcNAQEFBQADgYEAooEexP/oPam1TP71SyuhxMb+uTrZbSQe
|
41
|
+
|
42
|
+
jVB+ExRwWadGwaNPUA56d39qwavwP+iu+3JpeonNMVvbWXF5naCX/dNFIeREHzER
|
43
|
+
|
44
|
+
ZDRQYMqru9TEMna6HD9zpcstF7vwThGovlOQ+3Y6plQ4nMzipXcZ9THqs65PIL0q
|
45
|
+
|
46
|
+
eabwpCbAopo=
|
47
|
+
|
48
|
+
-----END CERTIFICATE-----
|
49
|
+
|
50
|
+
'
|
51
|
+
date: 2012-03-25 00:00:00.000000000 Z
|
39
52
|
dependencies: []
|
40
53
|
description:
|
41
54
|
email: sixarm@sixarm.com
|
@@ -44,11 +57,8 @@ extensions: []
|
|
44
57
|
extra_rdoc_files: []
|
45
58
|
files:
|
46
59
|
- .gemtest
|
47
|
-
- CHANGELOG.txt
|
48
|
-
- INSTALL.txt
|
49
|
-
- LICENSE.txt
|
50
60
|
- Rakefile
|
51
|
-
- README.
|
61
|
+
- README.md
|
52
62
|
- VERSION
|
53
63
|
- lib/sixarm_ruby_person_name.rb
|
54
64
|
- test/sixarm_ruby_person_name_test.rb
|
@@ -72,7 +82,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
72
82
|
version: '0'
|
73
83
|
requirements: []
|
74
84
|
rubyforge_project:
|
75
|
-
rubygems_version: 1.8.
|
85
|
+
rubygems_version: 1.8.19
|
76
86
|
signing_key:
|
77
87
|
specification_version: 3
|
78
88
|
summary: SixArm.com » Ruby » PersonName mixin methods to calculate a person's full
|
metadata.gz.sig
CHANGED
Binary file
|
data/CHANGELOG.txt
DELETED
data/INSTALL.txt
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
|
2
|
-
= SixArm.com Ruby Gem Install
|
3
|
-
|
4
|
-
|
5
|
-
First-time users: add our gem certificate and source.
|
6
|
-
When you do this once, it works for all our gems.
|
7
|
-
|
8
|
-
sudo wget http://sixarm.com/sixarm.pem
|
9
|
-
sudo gem cert --add sixarm.pem
|
10
|
-
sudo gem sources --add http://sixarm.com
|
11
|
-
|
12
|
-
Install the gem with advanced options.
|
13
|
-
|
14
|
-
sudo gem install sixarm_ruby_person_name --test --trust-policy HighSecurity
|
15
|
-
|
16
|
-
|
17
|
-
== Notes
|
18
|
-
|
19
|
-
Do you have any questions, comments, suggestions, or feedback?
|
20
|
-
Let us know, we're happy to help. Our email is sixarm@sixarm.com
|
21
|
-
|
22
|
-
Do you want to create your own high security gems?
|
23
|
-
Learn how at http://www.rubygems.org/read/chapter/21
|
24
|
-
|
25
|
-
To see your current gem certificate list:
|
26
|
-
|
27
|
-
sudo gem cert --list
|
28
|
-
|
29
|
-
Our cert looks like this:
|
30
|
-
|
31
|
-
/C=US/ST=California/L=San Francisco/O=SixArm/CN=sixarm.com
|
32
|
-
|
data/LICENSE.txt
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
LICENSE
|
2
|
-
|
3
|
-
You may choose any of these open source licenses:
|
4
|
-
|
5
|
-
- Apache License
|
6
|
-
- BSD License
|
7
|
-
- CreativeCommons License, Non-commercial Share Alike
|
8
|
-
- GNU General Public License Version 2 (GPL 2)
|
9
|
-
- GNU Lesser General Public License (LGPL)
|
10
|
-
- MIT License
|
11
|
-
- Perl Artistic License
|
12
|
-
- Ruby License
|
13
|
-
|
14
|
-
The software is provided "as is", without warranty of any kind,
|
15
|
-
express or implied, including but not limited to the warranties of
|
16
|
-
merchantability, fitness for a particular purpose and noninfringement.
|
17
|
-
|
18
|
-
In no event shall the authors or copyright holders be liable for any
|
19
|
-
claim, damages or other liability, whether in an action of contract,
|
20
|
-
tort or otherwise, arising from, out of or in connection with the
|
21
|
-
software or the use or other dealings in the software.
|
22
|
-
|
23
|
-
This license is for the included software that is created by SixArm;
|
24
|
-
some of the included software may have its own licenses, copyrights,
|
25
|
-
authors, etc. and these do take precedence over the SixArm license.
|
data/README.rdoc
DELETED
@@ -1,52 +0,0 @@
|
|
1
|
-
= SixArm.com » Ruby » PersonName gem accesses a person's name from ActiveRecord fields
|
2
|
-
|
3
|
-
Author:: Joel Parker Henderson, joel@joelparkerhenderson.com
|
4
|
-
Copyright:: Copyright (c) 2006-2011 Joel Parker Henderson
|
5
|
-
License:: See LICENSE.txt file
|
6
|
-
|
7
|
-
Access a person's name from the fields of a model in several combinations by using these methods:
|
8
|
-
* first_name_middle_name
|
9
|
-
* first_name_middle_initial
|
10
|
-
* first_name_middle_initial_last_name
|
11
|
-
* first_name_last_name
|
12
|
-
* full_name
|
13
|
-
* list_name
|
14
|
-
* initials
|
15
|
-
|
16
|
-
*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).
|
17
|
-
|
18
|
-
However all of these fields which are present must be strings.
|
19
|
-
|
20
|
-
==Example
|
21
|
-
|
22
|
-
class User < ActiveRecord::Base
|
23
|
-
include PersonName
|
24
|
-
end
|
25
|
-
|
26
|
-
user=User.create(
|
27
|
-
first_name => 'Martin',
|
28
|
-
middle_name => 'Luther',
|
29
|
-
last_name => 'King'
|
30
|
-
)
|
31
|
-
|
32
|
-
user.full_name => "Martin Luther King"
|
33
|
-
user.list_name => "King, Martin Luther"
|
34
|
-
user.initials => "MLK"
|
35
|
-
|
36
|
-
==Performance Tip
|
37
|
-
|
38
|
-
To make these very fast in Rails, you can use memoize:
|
39
|
-
|
40
|
-
class User < ActiveRecord::Base
|
41
|
-
extend ActiveSupport::Memoizable
|
42
|
-
include PersonName
|
43
|
-
memoize :first_name_middle_name,
|
44
|
-
:first_name_middle_initial,
|
45
|
-
:first_name_middle_initial_last_name,
|
46
|
-
:first_name_last_name,
|
47
|
-
:full_name,
|
48
|
-
:list_name,
|
49
|
-
:initials
|
50
|
-
end
|
51
|
-
|
52
|
-
|