From 57ee06f9fed201de11a9b6a7ff1e0eb2d34d1eb5 Mon Sep 17 00:00:00 2001 From: "Jurriaan H. Spaaks" Date: Tue, 5 Sep 2023 15:06:44 +0200 Subject: [PATCH] cleaned up if statement for apalike author name concatenation --- src/cffconvert/lib/cff_1_0_x/apalike.py | 12 +++++++----- src/cffconvert/lib/cff_1_1_x/apalike.py | 12 +++++++----- src/cffconvert/lib/cff_1_2_x/apalike.py | 12 +++++++----- src/cffconvert/lib/cff_1_3_x/apalike.py | 12 +++++++----- 4 files changed, 28 insertions(+), 20 deletions(-) diff --git a/src/cffconvert/lib/cff_1_0_x/apalike.py b/src/cffconvert/lib/cff_1_0_x/apalike.py index a94f499d..c7f93f60 100644 --- a/src/cffconvert/lib/cff_1_0_x/apalike.py +++ b/src/cffconvert/lib/cff_1_0_x/apalike.py @@ -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): diff --git a/src/cffconvert/lib/cff_1_1_x/apalike.py b/src/cffconvert/lib/cff_1_1_x/apalike.py index cae1f3ba..7a6cf3a0 100644 --- a/src/cffconvert/lib/cff_1_1_x/apalike.py +++ b/src/cffconvert/lib/cff_1_1_x/apalike.py @@ -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): diff --git a/src/cffconvert/lib/cff_1_2_x/apalike.py b/src/cffconvert/lib/cff_1_2_x/apalike.py index 3965ec1b..8951119b 100644 --- a/src/cffconvert/lib/cff_1_2_x/apalike.py +++ b/src/cffconvert/lib/cff_1_2_x/apalike.py @@ -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): diff --git a/src/cffconvert/lib/cff_1_3_x/apalike.py b/src/cffconvert/lib/cff_1_3_x/apalike.py index ce99135e..83514558 100644 --- a/src/cffconvert/lib/cff_1_3_x/apalike.py +++ b/src/cffconvert/lib/cff_1_3_x/apalike.py @@ -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):