Skip to content

Commit

Permalink
Added aastex.Author.orcid field. (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
byrdie authored Jun 4, 2024
1 parent 6e6a317 commit ac45804
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
12 changes: 11 additions & 1 deletion aastex/_aastex.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ class Author(pylatex.base_classes.LatexObject):
affiliation: Affiliation
"""The organization affiliated with the author"""

orcid: None | str = None
"""The optional ORCID of the author."""

email: None | str = None
"""
The optional email address of the author.
Expand All @@ -88,8 +91,15 @@ class Author(pylatex.base_classes.LatexObject):
"""

def dumps(self) -> str:
author = pylatex.Command("author", self.name).dumps()

author = pylatex.Command(
command="author",
arguments=self.name,
options=NoEscape(self.orcid) if self.orcid is not None else None,
).dumps()

affilation = self.affiliation.dumps()

result = f"{author}\n{affilation}"

if self.email is not None:
Expand Down
7 changes: 7 additions & 0 deletions aastex/_tests/test_aastex.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def test_dumps(self, a: aastex.Affiliation):
aastex.Author(
name="Jane Doe",
affiliation=aastex.Affiliation("Fancy University"),
orcid="0000-0000-0000-0000",
email="jane.doe@tmp.com",
),
],
Expand All @@ -52,6 +53,12 @@ def test_name(self, a: aastex.Author):
def test_affiliation(self, a: aastex.Author):
assert isinstance(a.affiliation, aastex.Affiliation)

def test_orcid(self, a: aastex.Author):
result = a.orcid
if result is not None:
assert isinstance(result, str)
assert result in a.dumps()

def test_email(self, a: aastex.Author):
result = a.email
if result is not None:
Expand Down

0 comments on commit ac45804

Please sign in to comment.