R/GatheringSiteCoordinates.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
#' # GatheringSiteCoordinates$new()
#'
#' @format
#' R6 class
#'
#' @title GatheringSiteCoordinates 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 GatheringSiteCoordinates objects.
#'
#'
#' @field longitudeDecimal  numeric
#'
#' @field latitudeDecimal  numeric
#'
#' @field gridCellSystem  character
#'
#' @field gridLatitudeDecimal  numeric
#'
#' @field gridLongitudeDecimal  numeric
#'
#' @field gridCellCode  character
#'
#' @field gridQualifier  character
#'
#' @field geoShape  Point
#'
#'
#'
#' @section Methods:
#' \describe{
#'
#' \item{\code{$new()}}{
#'
#'   Constructor GatheringSiteCoordinates object.
#'
#' }
#' \item{\code{$fromList(GatheringSiteCoordinatesList)}}{
#'
#'   Create GatheringSiteCoordinates object from list.
#'
#' }
#'
#' \item{\code{$toList()}}{
#'
#'   Get list representation of GatheringSiteCoordinates.
#'
#' }
#' \item{\code{fromJSONString(GatheringSiteCoordinatesJson)}}{
#'
#'   Create GatheringSiteCoordinates object from JSON.
#'
#' }
#' \item{\code{toJSONString(pretty=TRUE)}}{
#'
#'   Get JSON representation of GatheringSiteCoordinates.
#'
#' }
#' }
#' @importFrom R6 R6Class
#' @importFrom jsonlite fromJSON toJSON
#' @export
GatheringSiteCoordinates <- R6::R6Class(
  "GatheringSiteCoordinates",
  public = list(
    `longitudeDecimal` = NULL,
    `latitudeDecimal` = NULL,
    `gridCellSystem` = NULL,
    `gridLatitudeDecimal` = NULL,
    `gridLongitudeDecimal` = NULL,
    `gridCellCode` = NULL,
    `gridQualifier` = NULL,
    `geoShape` = NULL,
    initialize = function(
                              `longitudeDecimal`,
                              `latitudeDecimal`,
                              `gridCellSystem`,
                              `gridLatitudeDecimal`,
                              `gridLongitudeDecimal`,
                              `gridCellCode`,
                              `gridQualifier`,
                              `geoShape`) {
      if (!missing(`longitudeDecimal`)) {
        stopifnot(
          is.numeric(`longitudeDecimal`),
          length(`longitudeDecimal`) == 1
        )
        self[["longitudeDecimal"]] <- `longitudeDecimal`
      }
      if (!missing(`latitudeDecimal`)) {
        stopifnot(
          is.numeric(`latitudeDecimal`),
          length(`latitudeDecimal`) == 1
        )
        self[["latitudeDecimal"]] <- `latitudeDecimal`
      }
      if (!missing(`gridCellSystem`)) {
        stopifnot(
          is.character(`gridCellSystem`),
          length(`gridCellSystem`) == 1
        )
        self[["gridCellSystem"]] <- `gridCellSystem`
      }
      if (!missing(`gridLatitudeDecimal`)) {
        stopifnot(
          is.numeric(`gridLatitudeDecimal`),
          length(`gridLatitudeDecimal`) == 1
        )
        self[["gridLatitudeDecimal"]] <- `gridLatitudeDecimal`
      }
      if (!missing(`gridLongitudeDecimal`)) {
        stopifnot(
          is.numeric(`gridLongitudeDecimal`),
          length(`gridLongitudeDecimal`) == 1
        )
        self[["gridLongitudeDecimal"]] <- `gridLongitudeDecimal`
      }
      if (!missing(`gridCellCode`)) {
        stopifnot(
          is.character(`gridCellCode`),
          length(`gridCellCode`) == 1
        )
        self[["gridCellCode"]] <- `gridCellCode`
      }
      if (!missing(`gridQualifier`)) {
        stopifnot(
          is.character(`gridQualifier`),
          length(`gridQualifier`) == 1
        )
        self[["gridQualifier"]] <- `gridQualifier`
      }
      if (!missing(`geoShape`)) {
        stopifnot(R6::is.R6(`geoShape`))
        self[["geoShape"]] <- `geoShape`
      }
    },
    toList = function() {
      GatheringSiteCoordinatesList <- list()
      if (!is.null(self[["longitudeDecimal"]])) {
        GatheringSiteCoordinatesList[["longitudeDecimal"]] <-
          self[["longitudeDecimal"]]
      }
      if (!is.null(self[["latitudeDecimal"]])) {
        GatheringSiteCoordinatesList[["latitudeDecimal"]] <-
          self[["latitudeDecimal"]]
      }
      if (!is.null(self[["gridCellSystem"]])) {
        GatheringSiteCoordinatesList[["gridCellSystem"]] <-
          self[["gridCellSystem"]]
      }
      if (!is.null(self[["gridLatitudeDecimal"]])) {
        GatheringSiteCoordinatesList[["gridLatitudeDecimal"]] <-
          self[["gridLatitudeDecimal"]]
      }
      if (!is.null(self[["gridLongitudeDecimal"]])) {
        GatheringSiteCoordinatesList[["gridLongitudeDecimal"]] <-
          self[["gridLongitudeDecimal"]]
      }
      if (!is.null(self[["gridCellCode"]])) {
        GatheringSiteCoordinatesList[["gridCellCode"]] <-
          self[["gridCellCode"]]
      }
      if (!is.null(self[["gridQualifier"]])) {
        GatheringSiteCoordinatesList[["gridQualifier"]] <-
          self[["gridQualifier"]]
      }
      if (!is.null(self[["geoShape"]])) {
        GatheringSiteCoordinatesList[["geoShape"]] <-
          self[["geoShape"]]$toList()
      }
      ## omit empty nested lists in returned list
      GatheringSiteCoordinatesList[vapply(
        GatheringSiteCoordinatesList,
        length,
        FUN.VALUE = integer(1)
      ) > 0]
    },
    fromList = function(GatheringSiteCoordinatesList,
                            typeMapping = NULL) {
      self[["longitudeDecimal"]] <-
        GatheringSiteCoordinatesList[["longitudeDecimal"]]
      self[["latitudeDecimal"]] <-
        GatheringSiteCoordinatesList[["latitudeDecimal"]]
      self[["gridCellSystem"]] <-
        GatheringSiteCoordinatesList[["gridCellSystem"]]
      self[["gridLatitudeDecimal"]] <-
        GatheringSiteCoordinatesList[["gridLatitudeDecimal"]]
      self[["gridLongitudeDecimal"]] <-
        GatheringSiteCoordinatesList[["gridLongitudeDecimal"]]
      self[["gridCellCode"]] <-
        GatheringSiteCoordinatesList[["gridCellCode"]]
      self[["gridQualifier"]] <-
        GatheringSiteCoordinatesList[["gridQualifier"]]
      self[["geoShape"]] <- Point$new()$fromList(
        GatheringSiteCoordinatesList[["geoShape"]],
        typeMapping = typeMapping
      )
      invisible(self)
    },
    toJSONString = function(pretty = TRUE) {
      jsonlite::toJSON(
        self$toList(),
        simplifyVector = TRUE,
        auto_unbox = TRUE,
        pretty = pretty
      )
    },
    fromJSONString = function(GatheringSiteCoordinatesJson,
                                  typeMapping = NULL) {
      GatheringSiteCoordinatesList <- jsonlite::fromJSON(
        GatheringSiteCoordinatesJson,
        simplifyVector = FALSE
      )
      self <- self$fromList(GatheringSiteCoordinatesList)
      invisible(self)
    },
    print = function(...) {
      ## print class name
      cat("<GatheringSiteCoordinates>\n")
      ## print all members with values
      cat("Fields:\n")
      if (typeof(self$longitudeDecimal) == "environment") {
        cat("\tlongitudeDecimal:\tobject of class", paste0("<", class(self$longitudeDecimal)[1], ">"), "\n")
      }
      else if (typeof(self$longitudeDecimal) == "list") {
        cat("\tlongitudeDecimal:\tlist of length", length(self$longitudeDecimal), "\n")
      }
      else {
        cat("\tlongitudeDecimal:\t", self$longitudeDecimal, "\n")
      }
      if (typeof(self$latitudeDecimal) == "environment") {
        cat("\tlatitudeDecimal:\tobject of class", paste0("<", class(self$latitudeDecimal)[1], ">"), "\n")
      }
      else if (typeof(self$latitudeDecimal) == "list") {
        cat("\tlatitudeDecimal:\tlist of length", length(self$latitudeDecimal), "\n")
      }
      else {
        cat("\tlatitudeDecimal:\t", self$latitudeDecimal, "\n")
      }
      if (typeof(self$gridCellSystem) == "environment") {
        cat("\tgridCellSystem:\tobject of class", paste0("<", class(self$gridCellSystem)[1], ">"), "\n")
      }
      else if (typeof(self$gridCellSystem) == "list") {
        cat("\tgridCellSystem:\tlist of length", length(self$gridCellSystem), "\n")
      }
      else {
        cat("\tgridCellSystem:\t", self$gridCellSystem, "\n")
      }
      if (typeof(self$gridLatitudeDecimal) == "environment") {
        cat("\tgridLatitudeDecimal:\tobject of class", paste0("<", class(self$gridLatitudeDecimal)[1], ">"), "\n")
      }
      else if (typeof(self$gridLatitudeDecimal) == "list") {
        cat("\tgridLatitudeDecimal:\tlist of length", length(self$gridLatitudeDecimal), "\n")
      }
      else {
        cat("\tgridLatitudeDecimal:\t", self$gridLatitudeDecimal, "\n")
      }
      if (typeof(self$gridLongitudeDecimal) == "environment") {
        cat("\tgridLongitudeDecimal:\tobject of class", paste0("<", class(self$gridLongitudeDecimal)[1], ">"), "\n")
      }
      else if (typeof(self$gridLongitudeDecimal) == "list") {
        cat("\tgridLongitudeDecimal:\tlist of length", length(self$gridLongitudeDecimal), "\n")
      }
      else {
        cat("\tgridLongitudeDecimal:\t", self$gridLongitudeDecimal, "\n")
      }
      if (typeof(self$gridCellCode) == "environment") {
        cat("\tgridCellCode:\tobject of class", paste0("<", class(self$gridCellCode)[1], ">"), "\n")
      }
      else if (typeof(self$gridCellCode) == "list") {
        cat("\tgridCellCode:\tlist of length", length(self$gridCellCode), "\n")
      }
      else {
        cat("\tgridCellCode:\t", self$gridCellCode, "\n")
      }
      if (typeof(self$gridQualifier) == "environment") {
        cat("\tgridQualifier:\tobject of class", paste0("<", class(self$gridQualifier)[1], ">"), "\n")
      }
      else if (typeof(self$gridQualifier) == "list") {
        cat("\tgridQualifier:\tlist of length", length(self$gridQualifier), "\n")
      }
      else {
        cat("\tgridQualifier:\t", self$gridQualifier, "\n")
      }
      if (typeof(self$geoShape) == "environment") {
        cat("\tgeoShape:\tobject of class", paste0("<", class(self$geoShape)[1], ">"), "\n")
      }
      else if (typeof(self$geoShape) == "list") {
        cat("\tgeoShape:\tlist of length", length(self$geoShape), "\n")
      }
      else {
        cat("\tgeoShape:\t", self$geoShape, "\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.