name_of_person 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -2
- data/README.md +1 -1
- data/lib/name_of_person/assignable_name.rb +1 -1
- data/lib/name_of_person/person_name.rb +2 -2
- data/name_of_person.gemspec +1 -1
- data/test/person_name_test.rb +48 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6e75bed8c641e0f6361203d37e575fd793e9a13ecb8cc1a2447b6c8b81e01a2c
|
4
|
+
data.tar.gz: 245209ff20495805ecd4cba96d532a77dfe41abf303d4aa5e3bb5362e5fb1998
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 444b437c826b0a5daeb4409b3ea4c9e71303c1c1ad00ac7e690581f20b84c6a02de625062b12f8356fd5f433fa8cd40b980fa848bb0afe59f18f95a41fb1e89b
|
7
|
+
data.tar.gz: a7de5f58c5f30780d6883f5f8a6a32b0eaee3ab514406446d85f6205449fbbf69703922e318c04def9cbe075229b553cf37834b3809218534b7eb000f058d9e1
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -30,7 +30,7 @@ name.first # => "David"
|
|
30
30
|
|
31
31
|
## Maintenance Expectations
|
32
32
|
|
33
|
-
This library is an extraction from Basecamp that's been sufficient in almost unaltered form for over 10 years. While contributions are always welcome, do not expect a lot of feature evolution beyond the basics. Feel free to fork this library if you'd like to add large upgrades like titulations or different
|
33
|
+
This library is an extraction from Basecamp that's been sufficient in almost unaltered form for over 10 years. While contributions are always welcome, do not expect a lot of feature evolution beyond the basics. Feel free to fork this library if you'd like to add large upgrades like titulations or different accommodations for other languages.
|
34
34
|
|
35
35
|
## License
|
36
36
|
|
@@ -5,7 +5,7 @@ module NameOfPerson
|
|
5
5
|
# Assigns first_name and last_name attributes as extracted from a supplied full name.
|
6
6
|
def name=(name)
|
7
7
|
full_name = NameOfPerson::PersonName.full(name)
|
8
|
-
self.first_name, self.last_name = full_name
|
8
|
+
self.first_name, self.last_name = full_name&.first, full_name&.last
|
9
9
|
end
|
10
10
|
|
11
11
|
# Returns a PersonName object created from the first_name and last_name attributes.
|
@@ -5,7 +5,7 @@ module NameOfPerson
|
|
5
5
|
attr_reader :first, :last
|
6
6
|
|
7
7
|
def self.full(full_name)
|
8
|
-
first, last = full_name.to_s.
|
8
|
+
first, last = full_name.to_s.squish.split(/\s/, 2)
|
9
9
|
new(first, last) if first.present?
|
10
10
|
end
|
11
11
|
|
@@ -42,7 +42,7 @@ module NameOfPerson
|
|
42
42
|
|
43
43
|
# Returns just the initials.
|
44
44
|
def initials
|
45
|
-
@initials ||= scan(
|
45
|
+
@initials ||= scan(/(\S)\S+/).join
|
46
46
|
end
|
47
47
|
|
48
48
|
# Returns a mentionable version of the familiar name
|
data/name_of_person.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'name_of_person'
|
3
|
-
s.version = '1.
|
3
|
+
s.version = '1.1.0'
|
4
4
|
s.authors = 'David Heinemeier Hansson'
|
5
5
|
s.email = 'david@basecamp.com'
|
6
6
|
s.summary = 'Presenting names of people in full, familiar, abbreviated, and initialized forms (but without titulation etc)'
|
data/test/person_name_test.rb
CHANGED
@@ -56,6 +56,21 @@ class PersonNameTest < ActiveSupport::TestCase
|
|
56
56
|
assert_equal "Foo Bars'", PersonName.new('Foo', 'Bars').possessive
|
57
57
|
end
|
58
58
|
|
59
|
+
test "initials" do
|
60
|
+
name = PersonName.full('David Heinemeier Hansson')
|
61
|
+
assert_equal 'DHH', name.initials
|
62
|
+
end
|
63
|
+
|
64
|
+
test "initials (full name with spaces)" do
|
65
|
+
name = PersonName.full(' David Heinemeier Hansson ')
|
66
|
+
assert_equal 'DHH', name.initials
|
67
|
+
end
|
68
|
+
|
69
|
+
test "initials for just a first name" do
|
70
|
+
name = PersonName.full('David')
|
71
|
+
assert_equal 'D', name.initials
|
72
|
+
end
|
73
|
+
|
59
74
|
test "from full name" do
|
60
75
|
name = PersonName.full('Will St. Clair')
|
61
76
|
assert_equal 'Will', name.first
|
@@ -69,6 +84,34 @@ class PersonNameTest < ActiveSupport::TestCase
|
|
69
84
|
assert_nil PersonName.full('')
|
70
85
|
end
|
71
86
|
|
87
|
+
test "full name with spaces at the edges of the string" do
|
88
|
+
name = PersonName.full(' Will St. Clair ')
|
89
|
+
assert_equal 'Will', name.first
|
90
|
+
assert_equal 'St. Clair', name.last
|
91
|
+
assert_equal 'Will St. Clair', name.full
|
92
|
+
end
|
93
|
+
|
94
|
+
test "full name with spaces between first and last name" do
|
95
|
+
name = PersonName.full('Will St. Clair')
|
96
|
+
assert_equal 'Will', name.first
|
97
|
+
assert_equal 'St. Clair', name.last
|
98
|
+
assert_equal 'Will St. Clair', name.full
|
99
|
+
end
|
100
|
+
|
101
|
+
test "full name with spaces between multiple last name words" do
|
102
|
+
name = PersonName.full('Will St. Clair')
|
103
|
+
assert_equal 'Will', name.first
|
104
|
+
assert_equal 'St. Clair', name.last
|
105
|
+
assert_equal 'Will St. Clair', name.full
|
106
|
+
end
|
107
|
+
|
108
|
+
test "full name with spaces everywhere" do
|
109
|
+
name = PersonName.full(' Will St. Clair ')
|
110
|
+
assert_equal 'Will', name.first
|
111
|
+
assert_equal 'St. Clair', name.last
|
112
|
+
assert_equal 'Will St. Clair', name.full
|
113
|
+
end
|
114
|
+
|
72
115
|
test "blank last name behaves the same as nil" do
|
73
116
|
name = PersonName.new('Baz', '')
|
74
117
|
assert_equal @first.full, name.full
|
@@ -82,6 +125,11 @@ class PersonNameTest < ActiveSupport::TestCase
|
|
82
125
|
assert_equal 'foob', @name.mentionable
|
83
126
|
end
|
84
127
|
|
128
|
+
test "mentionable with first name" do
|
129
|
+
name = PersonName.full('Will')
|
130
|
+
assert_equal 'wil', name.mentionable
|
131
|
+
end
|
132
|
+
|
85
133
|
test "mentionable with three names" do
|
86
134
|
name = PersonName.full('Will St. Clair')
|
87
135
|
assert_equal 'wills', name.mentionable
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: name_of_person
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Heinemeier Hansson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-01-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|