R/SummarySourceSystem.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
#' # SummarySourceSystem$new()
#'
#' @format
#' R6 class
#'
#' @title SummarySourceSystem 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 SummarySourceSystem objects.
#'
#'
#' @field code  character
#'
#'
#'
#' @section Methods:
#' \describe{
#'
#' \item{\code{$new()}}{
#'
#'   Constructor SummarySourceSystem object.
#'
#' }
#' \item{\code{$fromList(SummarySourceSystemList)}}{
#'
#'   Create SummarySourceSystem object from list.
#'
#' }
#'
#' \item{\code{$toList()}}{
#'
#'   Get list representation of SummarySourceSystem.
#'
#' }
#' \item{\code{fromJSONString(SummarySourceSystemJson)}}{
#'
#'   Create SummarySourceSystem object from JSON.
#'
#' }
#' \item{\code{toJSONString(pretty=TRUE)}}{
#'
#'   Get JSON representation of SummarySourceSystem.
#'
#' }
#' }
#' @importFrom R6 R6Class
#' @importFrom jsonlite fromJSON toJSON
#' @export
SummarySourceSystem <- R6::R6Class(
  "SummarySourceSystem",
  public = list(
    `code` = NULL,
    initialize = function(
                              `code`) {
      if (!missing(`code`)) {
        stopifnot(
          is.character(`code`),
          length(`code`) == 1
        )
        self[["code"]] <- `code`
      }
    },
    toList = function() {
      SummarySourceSystemList <- list()
      if (!is.null(self[["code"]])) {
        SummarySourceSystemList[["code"]] <-
          self[["code"]]
      }
      ## omit empty nested lists in returned list
      SummarySourceSystemList[vapply(
        SummarySourceSystemList,
        length,
        FUN.VALUE = integer(1)
      ) > 0]
    },
    fromList = function(SummarySourceSystemList,
                            typeMapping = NULL) {
      self[["code"]] <-
        SummarySourceSystemList[["code"]]
      invisible(self)
    },
    toJSONString = function(pretty = TRUE) {
      jsonlite::toJSON(
        self$toList(),
        simplifyVector = TRUE,
        auto_unbox = TRUE,
        pretty = pretty
      )
    },
    fromJSONString = function(SummarySourceSystemJson,
                                  typeMapping = NULL) {
      SummarySourceSystemList <- jsonlite::fromJSON(
        SummarySourceSystemJson,
        simplifyVector = FALSE
      )
      self <- self$fromList(SummarySourceSystemList)
      invisible(self)
    },
    print = function(...) {
      ## print class name
      cat("<SummarySourceSystem>\n")
      ## print all members with values
      cat("Fields:\n")
      if (typeof(self$code) == "environment") {
        cat("\tcode:\tobject of class", paste0("<", class(self$code)[1], ">"), "\n")
      }
      else if (typeof(self$code) == "list") {
        cat("\tcode:\tlist of length", length(self$code), "\n")
      }
      else {
        cat("\tcode:\t", self$code, "\n")
      }
      ## print all methods
      cat("Methods:\n")
      cat("\tfromJSONString\n")
      cat("\ttoJSONString\n")
      cat("\tfromList\n")
      cat("\ttoList\n")
      cat("\tprint\n")
      invisible(self)
    }
  )
)
naturalis/nbaR documentation built on Nov. 12, 2023, 4:47 p.m.