R/openapi/dataset_type.R

Defines functions .parse_DatasetType

#' @docType class
#' @title DatasetType
#' @description DatasetType Class
#' @format An \code{R6Class} generator object
#' @importFrom R6 R6Class
#' @importFrom jsonlite fromJSON toJSON
#' @keywords internal
DatasetType <- R6::R6Class(
  "DatasetType",
  public = list(

    #' @description
    #' Initialize a new DatasetType class.
    #'
    #' @param ... Optional arguments.
    initialize = function(...) {
      local.optional.var <- list(...)
      val <- unlist(local.optional.var)
      enumvec <- .parse_DatasetType()

      if (length(val) == 0L) {
        val = "DUMMY_ENUM"
      } else {
        stopifnot(length(val) == 1L)
      }

      if (!val %in% enumvec) {
        if (!(val=="DUMMY_ENUM")) {
          stop("Use one of the valid values: ",
            paste0(enumvec, collapse = ", "))
        }
        warning("Initializing DatasetType with DUMMY_ENUM. Use one of the valid values: ",
          paste0(enumvec, collapse = ", "),
          ". If you did not manually initialize DatasetType, this may already be overwritten by an enum loaded from a JSON config.")
      }
      private$value <- val
    },

    #' @description
    #' To JSON String
    #'
    #' @return DatasetType in JSON format
    toJSON = function() {
        jsonlite::toJSON(private$value, auto_unbox = TRUE)
    },

    #' @description
    #' Deserialize JSON string into an instance of DatasetType
    #'
    #' @param input_json the JSON input
    #'
    #' @return the instance of DatasetType
    fromJSON = function(input_json) {
      private$value <- jsonlite::fromJSON(input_json,
          simplifyVector = FALSE)
      self
    },

    #' @description
    #' To JSON String
    #'
    #' @return DatasetType in JSON format
    toJSONString = function() {
      jsonlite::toJSON(private$value,
          auto_unbox = TRUE)
    },

    #' @description
    #' Deserialize JSON string into an instance of DatasetType
    #'
    #' @param input_json the JSON input
    #'
    #' @return the instance of DatasetType
    fromJSONString = function(input_json) {
      private$value <- jsonlite::fromJSON(input_json,
          simplifyVector = TRUE)
      self
    }
  ),
  private = list(
    value = NULL
  )
)

# # add to utils.R
# .parse_DatasetType <- function(vals) {
#   res <- gsub("^\\[|\\]$", "", "[PREDICTION]")
#   unlist(strsplit(res, ", "))
# }

# Enum definition
.parse_DatasetType <- function() {
  c("PREDICTION", "DUMMY_ENUM")
}
KinkyDesign/jaqpotr documentation built on Nov. 27, 2024, 1:20 a.m.