webget_ruby_person_name 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1 @@
1
+ i�#���ua�g
@@ -0,0 +1,12 @@
1
+ LICENSE
2
+
3
+ You may choose any of these licenses:
4
+
5
+ - CreativeCommons License, Non-commercial Share Alike
6
+ - LGPL, GNU Lesser General Public License
7
+ - MIT License
8
+ - Ruby License
9
+
10
+ THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
11
+ IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
12
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
@@ -0,0 +1,38 @@
1
+
2
+ = WebGet Ruby Gem: PersonName
3
+
4
+ Author:: Joel Parker Henderson, joelparkerhenderson@gmail.com
5
+ Copyright:: Copyright (c) 2006-2010 Joel Parker Henderson
6
+ License:: CreativeCommons License, Non-commercial Share Alike
7
+ License:: LGPL, GNU Lesser General Public License
8
+
9
+ Return the person's name in various ways.
10
+
11
+ ==Example
12
+ class User < ActiveRecord::Base
13
+ include PersonName
14
+ end
15
+
16
+ u=User.new
17
+ u.first_name = 'Zora'
18
+ u.middle_name = 'Neale'
19
+ u.last_name = 'Hurston'
20
+
21
+ u.full_name => "Zora Neale Hurston"
22
+ u.list_name => "Hurston, Zora Neale"
23
+ u.first_name_middle_name => "Zora Neale"
24
+ u.first_name_middle_initial_last_name => "Zora N Hurston"
25
+
26
+ ==Suggestion
27
+
28
+ To make these very fast in Rails, try using the memoize approach:
29
+ class User < ActiveRecord::Base
30
+ include PersonName
31
+ memoize :full_name
32
+ memoize :list_name
33
+ end
34
+
35
+ ==Notes
36
+
37
+ The first_name, middle_name, and last_name fields must be strings.
38
+
@@ -0,0 +1,141 @@
1
+ =begin rdoc
2
+
3
+ = WebGet Ruby Gem: PersonName
4
+
5
+ Author:: Joel Parker Henderson, joelparkerhenderson@gmail.com
6
+ Copyright:: Copyright (c) 2006-2010 Joel Parker Henderson
7
+ License:: CreativeCommons License, Non-commercial Share Alike
8
+ License:: LGPL, GNU Lesser General Public License
9
+
10
+ Return the person's name in various ways.
11
+
12
+ ==Example
13
+ class User < ActiveRecord::Base
14
+ include PersonName
15
+ end
16
+
17
+ u=User.new
18
+ u.first_name = 'Zora'
19
+ u.middle_name = 'Neale'
20
+ u.last_name = 'Hurston'
21
+
22
+ u.full_name => "Zora Neale Hurston"
23
+ u.list_name => "Hurston, Zora Neale"
24
+ u.first_name_middle_name => "Zora Neale"
25
+ u.first_name_middle_initial_last_name => "Zora N Hurston"
26
+
27
+ ==Suggestion
28
+
29
+ To make these very fast in Rails, try using the memoize approach:
30
+ class User < ActiveRecord::Base
31
+ include PersonName
32
+ memoize :full_name
33
+ memoize :list_name
34
+ end
35
+
36
+ ==Notes
37
+
38
+ The first_name, middle_name, and last_name fields must be strings.
39
+
40
+ =end
41
+
42
+
43
+ module PersonName
44
+
45
+
46
+ # Return true iff the person has a first name and its non-blank
47
+
48
+ def first_name?
49
+ respond_to?(:first_name) and first_name and first_name!='' and first_name.strip!=''
50
+ end
51
+
52
+
53
+ # Return true iff the person has a middle name and its non-blank
54
+
55
+ def middle_name?
56
+ respond_to?(:middle_name) and middle_name and middle_name!='' and middle_name.strip!=''
57
+ end
58
+
59
+
60
+ # Return true iff the person has a last name and its non-blank
61
+
62
+ def last_name?
63
+ respond_to?(:last_name) and last_name and last_name!='' and last_name.strip!=''
64
+ end
65
+
66
+
67
+ # Return the person's first name + middle name
68
+ #
69
+ # ==Example
70
+ # u.first_name_middle_name => "Zora Neale"
71
+
72
+ def first_name_middle_name
73
+ pieces = []
74
+ (pieces << first_name) if first_name?
75
+ (pieces << middle_name) if middle_name?
76
+ return pieces.join(' ')
77
+ end
78
+
79
+
80
+ # Return the person's first name + middle initial
81
+ #
82
+ # ==Example
83
+ # u.first_name_middle_initial => "Zora N"
84
+
85
+ def first_name_middle_initial
86
+ pieces = []
87
+ (pieces << first_name) if first_name?
88
+ (pieces << middle_name[0...1]) if middle_name?
89
+ return pieces.join(' ')
90
+ end
91
+
92
+
93
+ # Return the person's first name + middle initial + last name
94
+ #
95
+ # ==Example
96
+ # u.first_name_middle_initial_last_name => "Zora N Hurston"
97
+
98
+ def first_name_middle_initial_last_name
99
+ pieces = []
100
+ (pieces << first_name) if first_name?
101
+ (pieces << middle_name[0...1]) if middle_name?
102
+ (pieces << last_name) if last_name?
103
+ return pieces.join(' ')
104
+ end
105
+
106
+
107
+ # Return the person's full name: first_name middle_name last_name
108
+ #
109
+ # ==Example
110
+ # u.full_name => "Zora Neale Hurston"
111
+ #
112
+ # This method skips any piece of the name that is missing or blank.
113
+
114
+ def full_name
115
+ pieces = []
116
+ (pieces << first_name) if first_name?
117
+ (pieces << middle_name) if middle_name?
118
+ (pieces << last_name) if last_name?
119
+ return pieces.join(' ')
120
+ end
121
+
122
+
123
+ # Return the person's list name: last_name, first_name middle_name
124
+ #
125
+ # ==Example
126
+ # u.list_name => "Hurston, Zora Neale"
127
+ #
128
+ # This method skips any piece of the name that is missing or blank.
129
+
130
+ def list_name
131
+ pieces = []
132
+ (pieces << first_name) if first_name?
133
+ (pieces << middle_name) if middle_name?
134
+ if last_name?
135
+ comma = pieces.size>0 ? ',' : ''
136
+ pieces.unshift(last_name+comma)
137
+ end
138
+ return pieces.join(' ')
139
+ end
140
+
141
+ end
@@ -0,0 +1,123 @@
1
+ require 'test/unit'
2
+ require 'webget_ruby_person_name'
3
+
4
+ class PersonNameTest < Test::Unit::TestCase
5
+
6
+ def test_first_name_middle_name
7
+ assert_equal("abc def",p("abc","def","ghi").first_name_middle_name)
8
+ assert_equal("abc" ,p("abc",nil ,"ghi").first_name_middle_name)
9
+ assert_equal("def" ,p(nil ,"def" ,"ghi").first_name_middle_name)
10
+ assert_equal("" ,p(nil ,nil ,"ghi").first_name_middle_name)
11
+ end
12
+
13
+ def test_first_name_middle_initial
14
+ assert_equal("abc d",p("abc","def","ghi").first_name_middle_initial)
15
+ assert_equal("abc" ,p("abc",nil ,"ghi").first_name_middle_initial)
16
+ assert_equal("d" ,p(nil ,"def" ,"ghi").first_name_middle_initial)
17
+ assert_equal("" ,p(nil ,nil ,"ghi").first_name_middle_initial)
18
+ end
19
+
20
+ def test_first_name_middle_initial_last_name_with_first_name
21
+ assert_equal("abc",p("abc",nil,nil).first_name_middle_initial_last_name)
22
+ end
23
+
24
+ def test_first_name_middle_initial_last_name_with_middle_name
25
+ assert_equal("d", p(nil,"def",nil).first_name_middle_initial_last_name)
26
+ end
27
+
28
+ def test_first_name_middle_initial_last_name_with_last_name
29
+ assert_equal("ghi",p(nil,nil,"ghi").first_name_middle_initial_last_name)
30
+ end
31
+
32
+ def test_first_name_middle_initial_last_name_with_first_name_and_middle_name
33
+ assert_equal("abc d",p("abc","def",nil).first_name_middle_initial_last_name)
34
+ end
35
+
36
+ def test_first_name_middle_initial_last_name_with_first_name_and_last_name
37
+ assert_equal("abc ghi",p("abc",nil,"ghi").first_name_middle_initial_last_name)
38
+ end
39
+
40
+ def test_first_name_middle_initial_last_name
41
+ p=Person.new("abc","def","ghi")
42
+ assert_equal("abc d ghi",p.first_name_middle_initial_last_name)
43
+ end
44
+
45
+ def test_full_name_with_first_name
46
+ assert_equal("abc",p("abc",nil,nil).full_name)
47
+ end
48
+
49
+ def test_full_name_with_middle_name
50
+ assert_equal("def",p(nil,"def",nil).full_name)
51
+ end
52
+
53
+ def test_full_name_with_last_name
54
+ assert_equal("ghi",p(nil,nil,"ghi").full_name)
55
+ end
56
+
57
+ def test_full_name_with_first_name_and_middle_name
58
+ assert_equal("abc def",p("abc","def",nil).full_name)
59
+ end
60
+
61
+ def test_full_name_with_first_name_and_last_name
62
+ assert_equal("abc ghi",p("abc",nil,"ghi").full_name)
63
+ end
64
+
65
+ def test_full_name_with_middle_name_and_last_name
66
+ assert_equal("def ghi",p(nil,"def","ghi").full_name)
67
+ end
68
+
69
+ def test_full_name
70
+ assert_equal("abc def ghi",p("abc","def","ghi").full_name)
71
+ end
72
+
73
+ def test_list_name_with_first_name
74
+ assert_equal("abc",p("abc",nil,nil).list_name)
75
+ end
76
+
77
+ def test_list_name_with_middle_name
78
+ assert_equal("def", p(nil,"def",nil).list_name)
79
+ end
80
+
81
+ def test_list_name_with_last_name
82
+ assert_equal("ghi",p(nil,nil,"ghi").list_name)
83
+ end
84
+
85
+ def test_list_name_with_first_name_and_middle_name
86
+ assert_equal("abc def",p("abc","def",nil).list_name)
87
+ end
88
+
89
+ def test_list_name_with_first_name_and_last_name
90
+ assert_equal("ghi, abc",p("abc",nil,"ghi").list_name)
91
+ end
92
+
93
+ def test_list_name_with_middle_name_and_last_name
94
+ assert_equal("ghi, def",p(nil,"def","ghi").list_name)
95
+ end
96
+
97
+ def test_list_name
98
+ assert_equal("ghi, abc def",p("abc","def","ghi").list_name)
99
+ end
100
+
101
+ # Factory
102
+ def p(first,middle,last)
103
+ Person.new(first,middle,last)
104
+ end
105
+
106
+ end
107
+
108
+
109
+ class Person
110
+
111
+ attr_accessor :first_name
112
+ attr_accessor :middle_name
113
+ attr_accessor :last_name
114
+
115
+ include PersonName
116
+
117
+ def initialize(first,middle,last)
118
+ @first_name=first
119
+ @middle_name=middle
120
+ @last_name=last
121
+ end
122
+
123
+ end
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: webget_ruby_person_name
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.2
5
+ platform: ruby
6
+ authors:
7
+ - WebGet
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
+ MIIDvDCCAyWgAwIBAgIJAIlSqEkDQaZIMA0GCSqGSIb3DQEBBQUAMIGbMQswCQYD
14
+ VQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNU2FuIEZyYW5j
15
+ aXNjbzETMBEGA1UEChMKV2ViR2V0LmNvbTETMBEGA1UECxMKV2ViR2V0LmNvbTET
16
+ MBEGA1UEAxMKV2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moUjGh3Z0ZR0JlhU0ln8899LuJ3
32
+ DXnLFY0cVuBnNDMOOFl8vk1qIcZjcTovhzgcixpG6Uk5qmUsKHRLQf4oQJx7TfLK
33
+ -----END CERTIFICATE-----
34
+
35
+ date: 2010-02-19 00:00:00 -08:00
36
+ default_executable:
37
+ dependencies: []
38
+
39
+ description:
40
+ email: webget@webget.com
41
+ executables: []
42
+
43
+ extensions: []
44
+
45
+ extra_rdoc_files: []
46
+
47
+ files:
48
+ - README.rdoc
49
+ - LICENSE.txt
50
+ - lib/webget_ruby_person_name.rb
51
+ has_rdoc: true
52
+ homepage: http://webget.com/
53
+ licenses: []
54
+
55
+ post_install_message:
56
+ rdoc_options: []
57
+
58
+ require_paths:
59
+ - lib
60
+ required_ruby_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: "0"
65
+ version:
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: "0"
71
+ version:
72
+ requirements: []
73
+
74
+ rubyforge_project:
75
+ rubygems_version: 1.3.5
76
+ signing_key:
77
+ specification_version: 3
78
+ summary: "WebGet Ruby Gem: PersonName mixin methods to calculate a person's full name, sortable name, etc."
79
+ test_files:
80
+ - test/webget_ruby_person_name_test.rb
Binary file