diff --git a/R/give_candygrams.R b/R/give_candygrams.R index 8d71397..257f472 100644 --- a/R/give_candygrams.R +++ b/R/give_candygrams.R @@ -6,7 +6,7 @@ #' #' @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 @@ -21,16 +21,20 @@ give_candygrams <- function(person, number, } - if (is.null(extra_message)) { + if (is.null(extra_message)) { extra_message <- add_commentary(person, number) - + } else { + extra_message <- glue::glue("{extra_message} {add_commentary(person, number)}") } + + + number <- str_to_title(as.english(number)) - glue::glue("{number} for {person}.") + stringr::str_trim(glue::glue("{number} for {person}.") + " " + extra_message) diff --git a/README.Rmd b/README.Rmd index d101a20..64d4815 100644 --- a/README.Rmd +++ b/README.Rmd @@ -108,4 +108,7 @@ give_candygrams("Glen Coco", 4) give_candygrams("Gretchen Weiners", 4) ``` - +```{r} +give_candygrams("Glen Coco", 4, + extra_message = "Happy Birthday.") +``` diff --git a/README.md b/README.md index 876c029..aec9184 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,6 @@ # meangirls - The goal of meangirls is to create quotes in the style of the 2004 @@ -82,7 +81,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 +91,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 +99,16 @@ 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. +``` + +``` r +give_candygrams("Glen Coco", 4, + extra_message = "Happy Birthday.") +#> [1] "Four for Glen Coco. Happy Birthday. You go, Glen Coco!" ``` diff --git a/tests/testthat/test-give_candygrams.R b/tests/testthat/test-give_candygrams.R index 56fd4f3..5442ae2 100644 --- a/tests/testthat/test-give_candygrams.R +++ b/tests/testthat/test-give_candygrams.R @@ -1,7 +1,7 @@ test_that("add_commentary compliments people with lots of grams", { - correct_result <- "You go, Glen Coco!" + correct_result <- "Four for Glen Coco. You go, Glen Coco!" - my_result <- add_commentary("Glen Coco", 4) + my_result <- give_candygrams("Glen Coco", 4) expect_equal(my_result, correct_result) }) diff --git a/tests/testthat/testthat-problems.rds b/tests/testthat/testthat-problems.rds new file mode 100644 index 0000000..d6b55c7 Binary files /dev/null and b/tests/testthat/testthat-problems.rds differ