Skip to content

Commit

Permalink
cleaned up if statement for apalike author name concatenation
Browse files Browse the repository at this point in the history
  • Loading branch information
jspaaks committed Sep 5, 2023
1 parent a3ed798 commit 57ee06f
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 20 deletions.
12 changes: 7 additions & 5 deletions src/cffconvert/lib/cff_1_0_x/apalike.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ def add_author(self):
authors_apalike = [ApalikeAuthor(a).as_string() for a in authors_cff]
authors_apalike_filtered = [a for a in authors_apalike if a is not None]
n_authors = len(authors_apalike_filtered)
if n_authors > 2:
self.author = ", ".join(authors_apalike_filtered[:-1]) + ", and " + authors_apalike_filtered[-1]
if n_authors == 2:
self.author = ", ".join(authors_apalike_filtered[:-1]) + " and " + authors_apalike_filtered[-1]
if n_authors == 1:
if n_authors < 1:
pass
elif n_authors == 1:
self.author = ", ".join(authors_apalike_filtered)
elif n_authors == 2:
self.author = ", ".join(authors_apalike_filtered[:-1]) + " and " + authors_apalike_filtered[-1]
else:
self.author = ", ".join(authors_apalike_filtered[:-1]) + ", and " + authors_apalike_filtered[-1]
return self

def add_year(self):
Expand Down
12 changes: 7 additions & 5 deletions src/cffconvert/lib/cff_1_1_x/apalike.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ def add_author(self):
authors_apalike = [ApalikeAuthor(a).as_string() for a in authors_cff]
authors_apalike_filtered = [a for a in authors_apalike if a is not None]
n_authors = len(authors_apalike_filtered)
if n_authors > 2:
self.author = ", ".join(authors_apalike_filtered[:-1]) + ", and " + authors_apalike_filtered[-1]
if n_authors == 2:
self.author = ", ".join(authors_apalike_filtered[:-1]) + " and " + authors_apalike_filtered[-1]
if n_authors == 1:
if n_authors < 1:
pass
elif n_authors == 1:
self.author = ", ".join(authors_apalike_filtered)
elif n_authors == 2:
self.author = ", ".join(authors_apalike_filtered[:-1]) + " and " + authors_apalike_filtered[-1]
else:
self.author = ", ".join(authors_apalike_filtered[:-1]) + ", and " + authors_apalike_filtered[-1]
return self

def add_year(self):
Expand Down
12 changes: 7 additions & 5 deletions src/cffconvert/lib/cff_1_2_x/apalike.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ def add_author(self):
authors_apalike = [ApalikeAuthor(a).as_string() for a in authors_cff]
authors_apalike_filtered = [a for a in authors_apalike if a is not None]
n_authors = len(authors_apalike_filtered)
if n_authors > 2:
self.author = ", ".join(authors_apalike_filtered[:-1]) + ", and " + authors_apalike_filtered[-1]
if n_authors == 2:
self.author = ", ".join(authors_apalike_filtered[:-1]) + " and " + authors_apalike_filtered[-1]
if n_authors == 1:
if n_authors < 1:
pass
elif n_authors == 1:
self.author = ", ".join(authors_apalike_filtered)
elif n_authors == 2:
self.author = ", ".join(authors_apalike_filtered[:-1]) + " and " + authors_apalike_filtered[-1]
else:
self.author = ", ".join(authors_apalike_filtered[:-1]) + ", and " + authors_apalike_filtered[-1]
return self

def add_year(self):
Expand Down
12 changes: 7 additions & 5 deletions src/cffconvert/lib/cff_1_3_x/apalike.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ def add_author(self):
authors_apalike = [ApalikeAuthor(a).as_string() for a in authors_cff]
authors_apalike_filtered = [a for a in authors_apalike if a is not None]
n_authors = len(authors_apalike_filtered)
if n_authors > 2:
self.author = ", ".join(authors_apalike_filtered[:-1]) + ", and " + authors_apalike_filtered[-1]
if n_authors == 2:
self.author = ", ".join(authors_apalike_filtered[:-1]) + " and " + authors_apalike_filtered[-1]
if n_authors == 1:
if n_authors < 1:
pass
elif n_authors == 1:
self.author = ", ".join(authors_apalike_filtered)
elif n_authors == 2:
self.author = ", ".join(authors_apalike_filtered[:-1]) + " and " + authors_apalike_filtered[-1]
else:
self.author = ", ".join(authors_apalike_filtered[:-1]) + ", and " + authors_apalike_filtered[-1]
return self

def add_year(self):
Expand Down

0 comments on commit 57ee06f

Please sign in to comment.