R/Path.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
#' # Path$new()
#'
#' @format
#' R6 class
#'
#' @title Path 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 Path objects.
#'
#'
#' @field purePath  character
#'
#'
#'
#' @section Methods:
#' \describe{
#'
#' \item{\code{$new()}}{
#'
#'   Constructor Path object.
#'
#' }
#' \item{\code{$fromList(PathList)}}{
#'
#'   Create Path object from list.
#'
#' }
#'
#' \item{\code{$toList()}}{
#'
#'   Get list representation of Path.
#'
#' }
#' \item{\code{fromJSONString(PathJson)}}{
#'
#'   Create Path object from JSON.
#'
#' }
#' \item{\code{toJSONString(pretty=TRUE)}}{
#'
#'   Get JSON representation of Path.
#'
#' }
#' }
#' @importFrom R6 R6Class
#' @importFrom jsonlite fromJSON toJSON
#' @export
Path <- R6::R6Class(
  "Path",
  public = list(
    `purePath` = NULL,
    initialize = function(
                              `purePath`) {
      if (!missing(`purePath`)) {
        self[["purePath"]] <- `purePath`
      }
    },
    toList = function() {
      PathList <- list()
      if (!is.null(self[["purePath"]])) {
        PathList[["purePath"]] <-
          self[["purePath"]]
      }
      ## omit empty nested lists in returned list
      PathList[vapply(
        PathList,
        length,
        FUN.VALUE = integer(1)
      ) > 0]
    },
    fromList = function(PathList,
                            typeMapping = NULL) {
      self[["purePath"]] <-
        PathList[["purePath"]]
      invisible(self)
    },
    toJSONString = function(pretty = TRUE) {
      jsonlite::toJSON(
        self$toList(),
        simplifyVector = TRUE,
        auto_unbox = TRUE,
        pretty = pretty
      )
    },
    fromJSONString = function(PathJson,
                                  typeMapping = NULL) {
      PathList <- jsonlite::fromJSON(
        PathJson,
        simplifyVector = FALSE
      )
      self <- self$fromList(PathList)
      invisible(self)
    },
    print = function(...) {
      ## print class name
      cat("<Path>\n")
      ## print all members with values
      cat("Fields:\n")
      if (typeof(self$purePath) == "environment") {
        cat("\tpurePath:\tobject of class", paste0("<", class(self$purePath)[1], ">"), "\n")
      }
      else if (typeof(self$purePath) == "list") {
        cat("\tpurePath:\tlist of length", length(self$purePath), "\n")
      }
      else {
        cat("\tpurePath:\t", self$purePath, "\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.