Skip to content

Commit 9a3d187

Browse files
committed
Add surnames attribute as aggregate of middle and last names
1 parent 8c55eb9 commit 9a3d187

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

docs/release_log.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ Release Log
22
===========
33
* 1.0.1 - August 30, 2018
44
- Fix overzealous regex for "Ph. D." (#43)
5+
- Add `surnames` attribute as aggregate of middle and last names
56
* 1.0.0 - August 30, 2018
67
- Fix support for nicknames in single quotes (#74)
78
- Change prefix handling to support prefixes on first names (#60)

nameparser/parser.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,21 @@ def nickname(self):
243243
parenthesis (``()``)
244244
"""
245245
return " ".join(self.nickname_list) or self.C.empty_attribute_default
246-
246+
247+
@property
248+
def surnames_list(self):
249+
"""
250+
List of middle names followed by last name.
251+
"""
252+
return self.middle_list + self.last_list
253+
254+
@property
255+
def surnames(self):
256+
"""
257+
A string of all middle names followed by the last name.
258+
"""
259+
return " ".join(self.surnames_list) or self.C.empty_attribute_default
260+
247261
### setter methods
248262

249263
def _set_list(self, attr, value):

tests.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,14 @@ def test_blank_name(self):
188188
self.m(hn.first, "", hn)
189189
self.m(hn.last, "", hn)
190190

191+
def test_surnames_list_attribute(self):
192+
hn = HumanName("John Edgar Casey Williams III")
193+
self.m(hn.surnames_list, ["Edgar", "Casey", "Williams"], hn)
194+
195+
def test_surnames_attribute(self):
196+
hn = HumanName("John Edgar Casey Williams III")
197+
self.m(hn.surnames, "Edgar Casey Williams", hn)
198+
191199

192200
class FirstNameHandlingTests(HumanNameTestBase):
193201
def test_first_name(self):
@@ -1438,7 +1446,6 @@ def test_parenthesis_and_quotes_together(self):
14381446
self.m(hn.nickname, "Jen Duff", hn)
14391447

14401448

1441-
14421449
class PrefixesTestCase(HumanNameTestBase):
14431450

14441451
def test_prefix(self):

0 commit comments

Comments
 (0)