Skip to content
Browse files

Added middle name flag to primary_name_parts

  • Loading branch information...
1 parent 94be246 commit 67a4eaf5747a1e393ea064f333cde406cb8cfab2 Alison Rowland committed Apr 11, 2012
Showing with 13 additions and 3 deletions.
  1. +5 −2 name_cleaver/name_cleaver.py
  2. +7 −0 name_cleaver/test_name_cleaver.py
  3. +1 −1 setup.py
View
7 name_cleaver/name_cleaver.py
@@ -286,8 +286,11 @@ def capitalize_and_punctuate_initials(self, name_part):
else:
return name_part
- def primary_name_parts(self):
- return [ self.first, self.last ]
+ def primary_name_parts(self, include_middle=False):
+ if include_middle:
+ return [ self.first, self.middle, self.last ]
+ else:
+ return [ self.first, self.last ]
View
7 name_cleaver/test_name_cleaver.py
@@ -90,6 +90,10 @@ def test_handles_empty_names(self):
def test_capitalize_irish_names(self):
self.assertEqual('Sean O\'Leary', str(PoliticianNameCleaver('SEAN O\'LEARY').parse()))
+ def test_primary_name_parts(self):
+ self.assertEqual(['Robert', 'Geoff', 'Smith'], PoliticianNameCleaver('Smith, Robert Geoff').parse().primary_name_parts(include_middle=True))
+ self.assertEqual(['Robert', 'Smith'], PoliticianNameCleaver('Smith, Robert Geoff').parse().primary_name_parts())
+
class TestOrganizationNameCleaver(unittest.TestCase):
@@ -203,6 +207,9 @@ def test_unfazed_by_weird_cop_cont_parenthetical_phrases(self):
def test_mr_and_mrs(self):
self.assertEqual('Kenneth L Lay', str(IndividualNameCleaver('LAY, KENNETH L MR & MRS').parse()))
+ def test_primary_name_parts(self):
+ self.assertEqual(['Robert', 'Geoff', 'Smith'], IndividualNameCleaver('Smith, Robert Geoff').parse().primary_name_parts(include_middle=True))
+ self.assertEqual(['Robert', 'Smith'], IndividualNameCleaver('Smith, Robert Geoff').parse().primary_name_parts())
class TestCapitalization(unittest.TestCase):
View
2 setup.py
@@ -7,7 +7,7 @@
setup(
name='name-cleaver',
- version='0.2.9',
+ version='0.2.10',
description='Name parser and formatter (for politicians, individuals, and organizations)',
long_description=readme,
author='Alison Rowland',

0 comments on commit 67a4eaf

Please sign in to comment.
Something went wrong with that request. Please try again.