Skip to content

Commit

Permalink
Make author list suffixes more flexible (#90)
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaudgallou authored Sep 2, 2024
1 parent a2b640c commit 94968e9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# plume (development version)

* `$get_author_list(suffix =)` is now slightly more flexible and will try less hard to sanitise author list suffixes (#90).

* `PlumeQuarto` no longer converts roles to lower case (#88).

* `PlumeQuarto` now supports authors' `degrees` field and the `group` affiliation property (#53).
Expand Down
18 changes: 8 additions & 10 deletions R/als.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,25 +38,23 @@ als_parse <- function(format) {
}

als_join <- function(x, marks) {
prev_item <- vector("character", 1L)
out <- map2_vec(x, marks, \(item, mark) {
if (is_blank(item) && str_contain(mark, "^")) {
if (is_empty(item) && str_contain(mark, "^")) {
return("^")
}
if (is_blank(item)) {
if (is_empty(item)) {
return(item)
}
if (is_empty(prev_item) && str_contain(mark, ",")) {
mark <- stringr::str_remove(mark, fixed(","))
}
prev_item <<- item
paste0(mark, item)
})
collapse(out)
}

als_clean <- function(x) {
for (pattern in c("(?<=^|\\^),|,$", "\\^{2}")) {
x <- str_remove_all(x, pattern)
}
x
}

als_make <- function(data, cols, format) {
rows <- itemise_rows(data, cols)
marks <- als_parse(format)
Expand All @@ -65,5 +63,5 @@ als_make <- function(data, cols, format) {
}
out <- map_vec(rows, \(row) als_join(row, marks$heads))
out <- paste0(out, marks$tail)
als_clean(out)
als_sanitise(out)
}
8 changes: 4 additions & 4 deletions tests/testthat/test-get-author-list.R
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ test_that("get_author_list() returns author list", {
aut$get_author_list("^a,^c"),
affix_to_authors("^", .a, .seps, "^", .c)
)
expect_equal(
aut$get_author_list("c^,a^"),
affix_to_authors(.c, "^", .seps, .a, "^")
)

expect_equal(
aut$get_author_list("a,,c"),
affix_to_authors(.a, .seps, .c)
)
expect_equal(
aut$get_author_list(",ac,"),
affix_to_authors(.a, .c)
)
expect_equal(
aut$get_author_list("^^ac^^"),
affix_to_authors("^", .a, .c, "^")
Expand Down

0 comments on commit 94968e9

Please sign in to comment.