diff --git a/NAMESPACE b/NAMESPACE index cc05d6b..4d860c2 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -8,3 +8,4 @@ export(really_pretty) importFrom(english,as.english) importFrom(stringr,str_detect) importFrom(stringr,str_to_title) +importFrom(stringr,str_trim) diff --git a/R/give_candygrams.R b/R/give_candygrams.R index 8d71397..61791da 100644 --- a/R/give_candygrams.R +++ b/R/give_candygrams.R @@ -6,34 +6,27 @@ #' #' @return A candy gram announcement #' -#' @importFrom stringr str_detect str_to_title +#' @importFrom stringr str_detect str_to_title str_trim #' @importFrom english as.english #' #' @export give_candygrams <- function(person, number, extra_message = NULL) { - stopifnot(number > 0) if (str_detect(person, "Gretchen")) { - return(cat("None for Gretchen Weiners.")) - } if (is.null(extra_message)) { - extra_message <- add_commentary(person, number) - } number <- str_to_title(as.english(number)) - glue::glue("{number} for {person}.") - - - + glue::glue("{number} for {person}. {extra_message}") |> + str_trim(side = "right") } #' Tacks commentary on to candygram announcement @@ -43,21 +36,15 @@ give_candygrams <- function(person, number, #' #' @return A string (possibly blank) add_commentary <- function(person, number) { - if (stringr::str_detect(person, "Aaron")) { - return("They are from Regina.") - } if (number > 3) { - return(glue::glue("You go, {person}!")) - } return("") - } diff --git a/README.md b/README.md index 876c029..e047dbe 100644 --- a/README.md +++ b/README.md @@ -82,7 +82,7 @@ number of candygrams a person gets. ``` r give_candygrams("Taylor Zimmerman", 2) -#> Two for Taylor Zimmerman. +#> [1] "Two for Taylor Zimmerman." ``` ### Extra comments @@ -92,7 +92,7 @@ You can also give extra commentary to your announcement: ``` r give_candygrams("Taylor Zimmerman", 2, extra_message = "Merry Christmas!") -#> Two for Taylor Zimmerman. +#> [1] "Two for Taylor Zimmerman. Merry Christmas!" ``` Some special cases trigger automatic extra commentary or special @@ -100,10 +100,10 @@ behavior: ``` r give_candygrams("Glen Coco", 4) -#> Four for Glen Coco. +#> [1] "Four for Glen Coco. You go, Glen Coco!" ``` ``` r give_candygrams("Gretchen Weiners", 4) -#> [1] "None for Grethen Weiners." +#> None for Gretchen Weiners. ```