sixarm_ruby_person_name 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data.tar.gz.sig ADDED
Binary file
data/.gemtest ADDED
File without changes
data/CHANGELOG.txt ADDED
@@ -0,0 +1,4 @@
1
+ CHANGELOG
2
+
3
+ 2012-01-24 1.0.4 Add #initals method. Add CHANGELOG.txt file. Update examples.
4
+
data/INSTALL.txt ADDED
@@ -0,0 +1,32 @@
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 ADDED
@@ -0,0 +1,25 @@
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 ADDED
@@ -0,0 +1,52 @@
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
+
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'rake'
3
+ require 'rake/testtask'
4
+
5
+ Rake::TestTask.new(:test) do |t|
6
+ t.libs << 'lib' << 'test'
7
+ t.pattern = 'test/*.rb'
8
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0.4
@@ -0,0 +1,122 @@
1
+ # -*- coding: utf-8 -*-
2
+ =begin rdoc
3
+ Please see README.rdoc
4
+ =end
5
+
6
+
7
+ module PersonName
8
+
9
+
10
+ # Return true iff the person has a first name and its non-blank
11
+
12
+ def first_name?
13
+ respond_to?(:first_name) and first_name and first_name!='' and first_name.strip!=''
14
+ end
15
+
16
+
17
+ # Return true iff the person has a middle name and its non-blank
18
+
19
+ def middle_name?
20
+ respond_to?(:middle_name) and middle_name and middle_name!='' and middle_name.strip!=''
21
+ end
22
+
23
+
24
+ # Return true iff the person has a last name and its non-blank
25
+
26
+ def last_name?
27
+ respond_to?(:last_name) and last_name and last_name!='' and last_name.strip!=''
28
+ end
29
+
30
+
31
+ # Return the person's first name + middle name
32
+ #
33
+ # ==Example
34
+ # u.first_name_middle_name => "Martin Luther"
35
+
36
+ def first_name_middle_name
37
+ pieces = []
38
+ (pieces << first_name) if first_name?
39
+ (pieces << middle_name) if middle_name?
40
+ return pieces.join(' ')
41
+ end
42
+
43
+
44
+ # Return the person's first name + middle initial
45
+ #
46
+ # ==Example
47
+ # u.first_name_middle_initial => "Martin N"
48
+
49
+ def first_name_middle_initial
50
+ pieces = []
51
+ (pieces << first_name) if first_name?
52
+ (pieces << middle_name[0...1]) if middle_name?
53
+ return pieces.join(' ')
54
+ end
55
+
56
+
57
+ # Return the person's first name + middle initial + last name
58
+ #
59
+ # ==Example
60
+ # u.first_name_middle_initial_last_name => "Martin N King"
61
+
62
+ def first_name_middle_initial_last_name
63
+ pieces = []
64
+ (pieces << first_name) if first_name?
65
+ (pieces << middle_name[0...1]) if middle_name?
66
+ (pieces << last_name) if last_name?
67
+ return pieces.join(' ')
68
+ end
69
+
70
+
71
+ # Return the person's full name: first_name middle_name last_name
72
+ #
73
+ # ==Example
74
+ # u.full_name => "Martin Luther King"
75
+ #
76
+ # This method skips any piece of the name that is missing or blank.
77
+
78
+ def full_name
79
+ pieces = []
80
+ (pieces << first_name) if first_name?
81
+ (pieces << middle_name) if middle_name?
82
+ (pieces << last_name) if last_name?
83
+ return pieces.join(' ')
84
+ end
85
+
86
+
87
+ # Return the person's list name: last_name, first_name middle_name
88
+ #
89
+ # ==Example
90
+ # u.list_name => "King, Martin Luther"
91
+ #
92
+ # This method skips any piece of the name that is missing or blank.
93
+
94
+ def list_name
95
+ pieces = []
96
+ (pieces << first_name) if first_name?
97
+ (pieces << middle_name) if middle_name?
98
+ if last_name?
99
+ comma = pieces.size>0 ? ',' : ''
100
+ pieces.unshift(last_name+comma)
101
+ end
102
+ return pieces.join(' ')
103
+ end
104
+
105
+
106
+ # Return the person's intials
107
+ #
108
+ # ==Example
109
+ # u.initials => "MLK"
110
+ #
111
+ # This method skips any piece of the name that is missing or blank.
112
+
113
+ def initials
114
+ s = ""
115
+ (s << first_name[0]) if first_name?
116
+ (s << middle_name[0]) if middle_name?
117
+ (s << last_name[0]) if last_name?
118
+ return s
119
+ end
120
+
121
+
122
+ end
@@ -0,0 +1,138 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'test/unit'
3
+ require 'simplecov'
4
+ SimpleCov.start
5
+ require 'sixarm_ruby_person_name'
6
+
7
+ class PersonNameTest < Test::Unit::TestCase
8
+
9
+ def test_first_name_middle_name
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
15
+
16
+ def test_first_name_middle_initial
17
+ assert_equal("abc d",p("abc","def","ghi").first_name_middle_initial)
18
+ assert_equal("abc" ,p("abc",nil ,"ghi").first_name_middle_initial)
19
+ assert_equal("d" ,p(nil ,"def" ,"ghi").first_name_middle_initial)
20
+ assert_equal("" ,p(nil ,nil ,"ghi").first_name_middle_initial)
21
+ end
22
+
23
+ def test_first_name_middle_initial_last_name_with_first_name
24
+ assert_equal("abc",p("abc",nil,nil).first_name_middle_initial_last_name)
25
+ end
26
+
27
+ def test_first_name_middle_initial_last_name_with_middle_name
28
+ assert_equal("d", p(nil,"def",nil).first_name_middle_initial_last_name)
29
+ end
30
+
31
+ def test_first_name_middle_initial_last_name_with_last_name
32
+ assert_equal("ghi",p(nil,nil,"ghi").first_name_middle_initial_last_name)
33
+ end
34
+
35
+ def test_first_name_middle_initial_last_name_with_first_name_and_middle_name
36
+ assert_equal("abc d",p("abc","def",nil).first_name_middle_initial_last_name)
37
+ end
38
+
39
+ def test_first_name_middle_initial_last_name_with_first_name_and_last_name
40
+ assert_equal("abc ghi",p("abc",nil,"ghi").first_name_middle_initial_last_name)
41
+ end
42
+
43
+ def test_first_name_middle_initial_last_name
44
+ p=Person.new("abc","def","ghi")
45
+ assert_equal("abc d ghi",p.first_name_middle_initial_last_name)
46
+ end
47
+
48
+ def test_full_name_with_first_name
49
+ assert_equal("abc",p("abc",nil,nil).full_name)
50
+ end
51
+
52
+ def test_full_name_with_middle_name
53
+ assert_equal("def",p(nil,"def",nil).full_name)
54
+ end
55
+
56
+ def test_full_name_with_last_name
57
+ assert_equal("ghi",p(nil,nil,"ghi").full_name)
58
+ end
59
+
60
+ def test_full_name_with_first_name_and_middle_name
61
+ assert_equal("abc def",p("abc","def",nil).full_name)
62
+ end
63
+
64
+ def test_full_name_with_first_name_and_last_name
65
+ assert_equal("abc ghi",p("abc",nil,"ghi").full_name)
66
+ end
67
+
68
+ def test_full_name_with_middle_name_and_last_name
69
+ assert_equal("def ghi",p(nil,"def","ghi").full_name)
70
+ end
71
+
72
+ def test_full_name
73
+ assert_equal("abc def ghi",p("abc","def","ghi").full_name)
74
+ end
75
+
76
+ def test_list_name_with_first_name
77
+ assert_equal("abc",p("abc",nil,nil).list_name)
78
+ end
79
+
80
+ def test_list_name_with_middle_name
81
+ assert_equal("def", p(nil,"def",nil).list_name)
82
+ end
83
+
84
+ def test_list_name_with_last_name
85
+ assert_equal("ghi",p(nil,nil,"ghi").list_name)
86
+ end
87
+
88
+ def test_list_name_with_first_name_and_middle_name
89
+ assert_equal("abc def",p("abc","def",nil).list_name)
90
+ end
91
+
92
+ def test_list_name_with_first_name_and_last_name
93
+ assert_equal("ghi, abc",p("abc",nil,"ghi").list_name)
94
+ end
95
+
96
+ def test_list_name_with_middle_name_and_last_name
97
+ assert_equal("ghi, def",p(nil,"def","ghi").list_name)
98
+ end
99
+
100
+ def test_list_name
101
+ assert_equal("ghi, abc def",p("abc","def","ghi").list_name)
102
+ end
103
+
104
+ def test_initials
105
+ assert_equal("adg",p("abc","def","ghi").initials)
106
+ end
107
+
108
+ def test_initials_with_first_name_and_middle_name
109
+ assert_equal("ad",p("abc","def",nil).initials)
110
+ end
111
+
112
+ def test_initials_with_first_name_and_last_name
113
+ assert_equal("ag",p("abc",nil,"ghi").initials)
114
+ end
115
+
116
+ # Factory
117
+ def p(first,middle,last)
118
+ Person.new(first,middle,last)
119
+ end
120
+
121
+ end
122
+
123
+
124
+ class Person
125
+
126
+ attr_accessor :first_name
127
+ attr_accessor :middle_name
128
+ attr_accessor :last_name
129
+
130
+ include PersonName
131
+
132
+ def initialize(first,middle,last)
133
+ @first_name=first
134
+ @middle_name=middle
135
+ @last_name=last
136
+ end
137
+
138
+ end
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sixarm_ruby_person_name
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.4
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - SixArm
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain:
12
+ - !binary |-
13
+ LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSURCRENDQW0yZ0F3SUJB
14
+ Z0lKQUtQd0VFVFU1YkhvTUEwR0NTcUdTSWIzRFFFQkJRVUFNR0F4Q3pBSkJn
15
+ TlYKQkFZVEFsVlRNUk13RVFZRFZRUUlFd3BEWVd4cFptOXlibWxoTVJZd0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TViSG9NQXdHQTFVZEV3UUYKTUFNQkFmOHdEUVlKS29aSWh2Y05BUUVGQlFB
33
+ RGdZRUFvb0VleFAvb1BhbTFUUDcxU3l1aHhNYit1VHJaYlNRZQpqVkIrRXhS
34
+ d1dhZEd3YU5QVUE1NmQzOXF3YXZ3UCtpdSszSnBlb25OTVZ2YldYRjVuYUNY
35
+ L2RORkllUkVIekVSClpEUlFZTXFydTlURU1uYTZIRDl6cGNzdEY3dndUaEdv
36
+ dmxPUSszWTZwbFE0bk16aXBYY1o5VEhxczY1UElMMHEKZWFid3BDYkFvcG89
37
+ Ci0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0K
38
+ date: 2012-01-25 00:00:00.000000000 Z
39
+ dependencies: []
40
+ description:
41
+ email: sixarm@sixarm.com
42
+ executables: []
43
+ extensions: []
44
+ extra_rdoc_files: []
45
+ files:
46
+ - .gemtest
47
+ - CHANGELOG.txt
48
+ - INSTALL.txt
49
+ - LICENSE.txt
50
+ - Rakefile
51
+ - README.rdoc
52
+ - VERSION
53
+ - lib/sixarm_ruby_person_name.rb
54
+ - test/sixarm_ruby_person_name_test.rb
55
+ homepage: http://sixarm.com/
56
+ licenses: []
57
+ post_install_message:
58
+ rdoc_options: []
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ! '>='
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ requirements: []
74
+ rubyforge_project:
75
+ rubygems_version: 1.8.15
76
+ signing_key:
77
+ specification_version: 3
78
+ summary: SixArm.com » Ruby » PersonName mixin methods to calculate a person's full
79
+ name, list name, initials, etc.
80
+ test_files:
81
+ - test/sixarm_ruby_person_name_test.rb
82
+ has_rdoc: true
metadata.gz.sig ADDED
Binary file