R/TaxonDescription.r

# Netherlands Biodiversity API
#
# Access to the digitised Natural History collection at the Naturalis Biodiversity Center
#
# OpenAPI spec version: v2
# Contact: support@naturalis.nl
# Generated by: https://github.com/swagger-api/swagger-codegen.git

#'
#' @docType class
#'
#' @format R6 class
#'
#' @usage
#' # TaxonDescription$new()
#'
#' @format
#' R6 class
#'
#' @title TaxonDescription Class
#'
#' @description
#' For more information on the NBA object model, please refer to the
#' official NBA documentation at
#' \href{https://docs.biodiversitydata.nl}{https://docs.biodiversitydata.nl} and
#' the NBA model and endpoints reference at
#' \href{https://docs.biodiversitydata.nl/endpoints-reference}{https://docs.biodiversitydata.nl/endpoints-reference}.
#'
#' @details Model class for TaxonDescription objects.
#'
#'
#' @field category  character
#'
#' @field description  character
#'
#' @field language  character
#'
#'
#'
#' @section Methods:
#' \describe{
#'
#' \item{\code{$new()}}{
#'
#'   Constructor TaxonDescription object.
#'
#' }
#' \item{\code{$fromList(TaxonDescriptionList)}}{
#'
#'   Create TaxonDescription object from list.
#'
#' }
#'
#' \item{\code{$toList()}}{
#'
#'   Get list representation of TaxonDescription.
#'
#' }
#' \item{\code{fromJSONString(TaxonDescriptionJson)}}{
#'
#'   Create TaxonDescription object from JSON.
#'
#' }
#' \item{\code{toJSONString(pretty=TRUE)}}{
#'
#'   Get JSON representation of TaxonDescription.
#'
#' }
#' }
#' @importFrom R6 R6Class
#' @importFrom jsonlite fromJSON toJSON
#' @export
TaxonDescription <- R6::R6Class(
  "TaxonDescription",
  public = list(
    `category` = NULL,
    `description` = NULL,
    `language` = NULL,
    initialize = function(
                              `category`,
                              `description`,
                              `language`) {
      if (!missing(`category`)) {
        stopifnot(
          is.character(`category`),
          length(`category`) == 1
        )
        self[["category"]] <- `category`
      }
      if (!missing(`description`)) {
        stopifnot(
          is.character(`description`),
          length(`description`) == 1
        )
        self[["description"]] <- `description`
      }
      if (!missing(`language`)) {
        stopifnot(
          is.character(`language`),
          length(`language`) == 1
        )
        self[["language"]] <- `language`
      }
    },
    toList = function() {
      TaxonDescriptionList <- list()
      if (!is.null(self[["category"]])) {
        TaxonDescriptionList[["category"]] <-
          self[["category"]]
      }
      if (!is.null(self[["description"]])) {
        TaxonDescriptionList[["description"]] <-
          self[["description"]]
      }
      if (!is.null(self[["language"]])) {
        TaxonDescriptionList[["language"]] <-
          self[["language"]]
      }
      ## omit empty nested lists in returned list
      TaxonDescriptionList[vapply(
        TaxonDescriptionList,
        length,
        FUN.VALUE = integer(1)
      ) > 0]
    },
    fromList = function(TaxonDescriptionList,
                            typeMapping = NULL) {
      self[["category"]] <-
        TaxonDescriptionList[["category"]]
      self[["description"]] <-
        TaxonDescriptionList[["description"]]
      self[["language"]] <-
        TaxonDescriptionList[["language"]]
      invisible(self)
    },
    toJSONString = function(pretty = TRUE) {
      jsonlite::toJSON(
        self$toList(),
        simplifyVector = TRUE,
        auto_unbox = TRUE,
        pretty = pretty
      )
    },
    fromJSONString = function(TaxonDescriptionJson,
                                  typeMapping = NULL) {
      TaxonDescriptionList <- jsonlite::fromJSON(
        TaxonDescriptionJson,
        simplifyVector = FALSE
      )
      self <- self$fromList(TaxonDescriptionList)
      invisible(self)
    },
    print = function(...) {
      ## print class name
      cat("<TaxonDescription>\n")
      ## print all members with values
      cat("Fields:\n")
      if (typeof(self$category) == "environment") {
        cat("\tcategory:\tobject of class", paste0("<", class(self$category)[1], ">"), "\n")
      }
      else if (typeof(self$category) == "list") {
        cat("\tcategory:\tlist of length", length(self$category), "\n")
      }
      else {
        cat("\tcategory:\t", self$category, "\n")
      }
      if (typeof(self$description) == "environment") {
        cat("\tdescription:\tobject of class", paste0("<", class(self$description)[1], ">"), "\n")
      }
      else if (typeof(self$description) == "list") {
        cat("\tdescription:\tlist of length", length(self$description), "\n")
      }
      else {
        cat("\tdescription:\t", self$description, "\n")
      }
      if (typeof(self$language) == "environment") {
        cat("\tlanguage:\tobject of class", paste0("<", class(self$language)[1], ">"), "\n")
      }
      else if (typeof(self$language) == "list") {
        cat("\tlanguage:\tlist of length", length(self$language), "\n")
      }
      else {
        cat("\tlanguage:\t", self$language, "\n")
      }
      ## print all methods
      cat("Methods:\n")
      cat("\tfromJSONString\n")
      cat("\ttoJSONString\n")
      cat("\tfromList\n")
      cat("\ttoList\n")
      cat("\tprint\n")
      invisible(self)
    }
  )
)
ropensci/nbaR documentation built on Nov. 12, 2023, 3:57 a.m.