name_of_person 1.1.1 → 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +15 -17
- data/README.md +8 -2
- data/lib/name_of_person/assignable_name.rb +1 -1
- data/lib/name_of_person/loaders/active_model_has_person_name.rb +8 -2
- data/lib/name_of_person/loaders/active_record_has_person_name.rb +2 -2
- data/lib/name_of_person/person_name.rb +12 -3
- data/name_of_person.gemspec +1 -2
- data/test/person_name_test.rb +31 -0
- metadata +7 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c68f3b0e0e4361dc4dd4d5214d1f896cee83276ba8b4654cacba1782766e50a3
|
4
|
+
data.tar.gz: 9d232052de3441c9201f48905d89d81d06560e9fc99ae2788c451b62a7b943ac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1895f409c69ac9131f7c949d8ef5d480f6a413b88d5afa91503930d98f6582680e54e27ce212d98dbb97bb16c4c08d11a26e90845ef0828b127b190bfaaf0bec
|
7
|
+
data.tar.gz: 3683027336a25105aa4c22638b532eebbfe311ada04e47569c303649e505fc25b3d6a29752a3911cb071f4839791b36e5f182b67d03cb2800e9dd1ad50e0d652
|
data/Gemfile.lock
CHANGED
@@ -1,38 +1,36 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
name_of_person (1.1.
|
4
|
+
name_of_person (1.1.2)
|
5
5
|
activesupport (>= 5.2.0)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
activemodel (
|
11
|
-
activesupport (=
|
12
|
-
activesupport (
|
10
|
+
activemodel (7.0.7.2)
|
11
|
+
activesupport (= 7.0.7.2)
|
12
|
+
activesupport (7.0.7.2)
|
13
13
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
14
|
-
i18n (>=
|
15
|
-
minitest (
|
16
|
-
tzinfo (~>
|
17
|
-
byebug (
|
18
|
-
concurrent-ruby (1.
|
19
|
-
i18n (1.1
|
14
|
+
i18n (>= 1.6, < 2)
|
15
|
+
minitest (>= 5.1)
|
16
|
+
tzinfo (~> 2.0)
|
17
|
+
byebug (11.1.3)
|
18
|
+
concurrent-ruby (1.2.2)
|
19
|
+
i18n (1.14.1)
|
20
|
+
concurrent-ruby (~> 1.0)
|
21
|
+
minitest (5.19.0)
|
22
|
+
rake (13.0.6)
|
23
|
+
tzinfo (2.0.6)
|
20
24
|
concurrent-ruby (~> 1.0)
|
21
|
-
minitest (5.11.3)
|
22
|
-
rake (12.3.1)
|
23
|
-
thread_safe (0.3.6)
|
24
|
-
tzinfo (1.2.5)
|
25
|
-
thread_safe (~> 0.1)
|
26
25
|
|
27
26
|
PLATFORMS
|
28
27
|
ruby
|
29
28
|
|
30
29
|
DEPENDENCIES
|
31
30
|
activemodel (>= 5.2.0)
|
32
|
-
bundler (~> 1.15)
|
33
31
|
byebug
|
34
32
|
name_of_person!
|
35
33
|
rake
|
36
34
|
|
37
35
|
BUNDLED WITH
|
38
|
-
|
36
|
+
2.4.18
|
data/README.md
CHANGED
@@ -22,6 +22,12 @@ person.name.abbreviated # => "D. Heinemeier Hansson"
|
|
22
22
|
person.name.sorted # => "Heinemeier Hansson, David"
|
23
23
|
person.name.mentionable # => "davidh"
|
24
24
|
person.name.possessive # => "David Heinemeier Hansson's"
|
25
|
+
person.name.possessive(:first) # => "David's"
|
26
|
+
person.name.possessive(:last) # => "Hansson's"
|
27
|
+
person.name.possessive(:initials) # => "DHH's"
|
28
|
+
person.name.possessive(:sorted) # => "Heinemeier Hansson, David's"
|
29
|
+
person.name.possessive(:abbreviated) # => "D. Heinemeier Hansson's"
|
30
|
+
|
25
31
|
|
26
32
|
# Use directly
|
27
33
|
name = NameOfPerson::PersonName.full("David Heinemeier Hansson")
|
@@ -43,9 +49,9 @@ require 'active_record'
|
|
43
49
|
require 'active_model'
|
44
50
|
```
|
45
51
|
|
46
|
-
##
|
52
|
+
## No further development is going to happen
|
47
53
|
|
48
|
-
This
|
54
|
+
This gem is essentially frozen, as the developers have decided to only deal with full names going forward in their applications. Feel free to fork this work, brand it under a new name, and continue development.
|
49
55
|
|
50
56
|
## License
|
51
57
|
|
@@ -10,7 +10,7 @@ module NameOfPerson
|
|
10
10
|
|
11
11
|
# Returns a PersonName object created from the first_name and last_name attributes.
|
12
12
|
def name
|
13
|
-
NameOfPerson::PersonName.new(first_name, last_name) if first_name
|
13
|
+
NameOfPerson::PersonName.new(first_name, last_name) if first_name.present?
|
14
14
|
end
|
15
15
|
end
|
16
16
|
end
|
@@ -1,3 +1,9 @@
|
|
1
|
-
if
|
2
|
-
ActiveModel
|
1
|
+
if ActiveSupport.gem_version < "7.1.0.alpha"
|
2
|
+
if defined?(ActiveModel)
|
3
|
+
ActiveModel::Model.send :include, NameOfPerson::HasPersonName
|
4
|
+
end
|
5
|
+
else
|
6
|
+
ActiveSupport.on_load(:active_model) do
|
7
|
+
include NameOfPerson::HasPersonName
|
8
|
+
end
|
3
9
|
end
|
@@ -1,3 +1,3 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
ActiveSupport.on_load(:active_record) do
|
2
|
+
include NameOfPerson::HasPersonName
|
3
3
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'active_support'
|
1
2
|
require 'active_support/core_ext/string'
|
2
3
|
|
3
4
|
module NameOfPerson
|
@@ -36,13 +37,21 @@ module NameOfPerson
|
|
36
37
|
end
|
37
38
|
|
38
39
|
# Returns full name with with trailing 's or ' if name ends in s.
|
39
|
-
def possessive
|
40
|
-
|
40
|
+
def possessive(method = :full)
|
41
|
+
whitelist = %i[full first last abbreviated sorted initials]
|
42
|
+
|
43
|
+
unless whitelist.include?(method.to_sym)
|
44
|
+
raise ArgumentError, 'Please provide a valid method'
|
45
|
+
end
|
46
|
+
|
47
|
+
name = public_send(method)
|
48
|
+
|
49
|
+
@possessive ||= "#{name}'#{'s' unless name.downcase.end_with?('s')}"
|
41
50
|
end
|
42
51
|
|
43
52
|
# Returns just the initials.
|
44
53
|
def initials
|
45
|
-
@initials ||= remove(/(\(|\[).*(\)|\])/).scan(/([[:word:]])[[:word:]]
|
54
|
+
@initials ||= remove(/(\(|\[).*(\)|\])/).scan(/([[:word:]])[[:word:]]*/i).join
|
46
55
|
end
|
47
56
|
|
48
57
|
# 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.1.
|
3
|
+
s.version = '1.1.2'
|
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)'
|
@@ -12,7 +12,6 @@ Gem::Specification.new do |s|
|
|
12
12
|
s.add_dependency 'activesupport', '>= 5.2.0'
|
13
13
|
|
14
14
|
s.add_development_dependency 'activemodel', '>= 5.2.0'
|
15
|
-
s.add_development_dependency 'bundler', '~> 1.15'
|
16
15
|
|
17
16
|
s.files = `git ls-files`.split("\n")
|
18
17
|
s.test_files = `git ls-files -- test/*`.split("\n")
|
data/test/person_name_test.rb
CHANGED
@@ -56,6 +56,32 @@ class PersonNameTest < ActiveSupport::TestCase
|
|
56
56
|
assert_equal "Foo Bars'", PersonName.new('Foo', 'Bars').possessive
|
57
57
|
end
|
58
58
|
|
59
|
+
test "possessive first" do
|
60
|
+
assert_equal "#{@name.first}'s", @name.possessive(:first)
|
61
|
+
end
|
62
|
+
|
63
|
+
test "possessive last" do
|
64
|
+
assert_equal "#{@name.last}'s", @name.possessive(:last)
|
65
|
+
end
|
66
|
+
|
67
|
+
test "possessive sorted" do
|
68
|
+
assert_equal "#{@name.sorted}'s", @name.possessive(:sorted)
|
69
|
+
end
|
70
|
+
|
71
|
+
test "possessive initials" do
|
72
|
+
assert_equal "#{@name.initials}'s", @name.possessive(:initials)
|
73
|
+
end
|
74
|
+
|
75
|
+
test "possessive abbreviated" do
|
76
|
+
assert_equal "#{@name.abbreviated}'s", @name.possessive(:abbreviated)
|
77
|
+
end
|
78
|
+
|
79
|
+
test "possessive with invalid arguments" do
|
80
|
+
assert_raise ArgumentError do
|
81
|
+
@name.possessive(:not_allowed)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
59
85
|
test "initials" do
|
60
86
|
name = PersonName.full('David Heinemeier Hansson')
|
61
87
|
assert_equal 'DHH', name.initials
|
@@ -86,6 +112,11 @@ class PersonNameTest < ActiveSupport::TestCase
|
|
86
112
|
assert_equal 'CM', name.initials
|
87
113
|
end
|
88
114
|
|
115
|
+
test "initials single letter" do
|
116
|
+
name = PersonName.full('C')
|
117
|
+
assert_equal 'C', name.initials
|
118
|
+
end
|
119
|
+
|
89
120
|
test "from full name" do
|
90
121
|
name = PersonName.full('Will St. Clair')
|
91
122
|
assert_equal 'Will', name.first
|
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.1.
|
4
|
+
version: 1.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Heinemeier Hansson
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-09-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -38,21 +38,7 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 5.2.0
|
41
|
-
|
42
|
-
name: bundler
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - "~>"
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '1.15'
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - "~>"
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '1.15'
|
55
|
-
description:
|
41
|
+
description:
|
56
42
|
email: david@basecamp.com
|
57
43
|
executables: []
|
58
44
|
extensions: []
|
@@ -77,7 +63,7 @@ homepage: https://github.com/basecamp/name_of_person
|
|
77
63
|
licenses:
|
78
64
|
- MIT
|
79
65
|
metadata: {}
|
80
|
-
post_install_message:
|
66
|
+
post_install_message:
|
81
67
|
rdoc_options: []
|
82
68
|
require_paths:
|
83
69
|
- lib
|
@@ -92,8 +78,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
92
78
|
- !ruby/object:Gem::Version
|
93
79
|
version: '0'
|
94
80
|
requirements: []
|
95
|
-
rubygems_version: 3.
|
96
|
-
signing_key:
|
81
|
+
rubygems_version: 3.4.18
|
82
|
+
signing_key:
|
97
83
|
specification_version: 4
|
98
84
|
summary: Presenting names of people in full, familiar, abbreviated, and initialized
|
99
85
|
forms (but without titulation etc)
|