R/game_sim_results.R

# Singlearity Baseball API
#
# Baseball optimization API using machine learning
#
# The version of the OpenAPI document: 0.1.1
# 
# Generated by: https://openapi-generator.tech

#' @docType class
#' @title GameSimResults
#'
#' @description GameSimResults Class
#'
#' @format An \code{R6Class} generator object
#'
#' @field home_score Home Score integer 
#'
#' @field away_score Away Score integer 
#'
#' @importFrom R6 R6Class
#' @importFrom jsonlite fromJSON toJSON
#' @export
GameSimResults <- R6::R6Class(
  'GameSimResults',
  public = list(
    `home_score` = NULL,
    `away_score` = NULL,
    initialize = function(
        `home_score`, `away_score`, ...
    ) {
      local.optional.var <- list(...)
      if (length(local.optional.var) > 0) {
        stop(paste("Unknown argument(s) in initialize of object GameSimResults:", paste(names(local.optional.var), collapse=", "), collapse=" "))
      }
      if (!missing(`home_score`)) {
        stopifnot(is.numeric(`home_score`), length(`home_score`) == 1)
        self$`home_score` <- `home_score`
      }
      if (!missing(`away_score`)) {
        stopifnot(is.numeric(`away_score`), length(`away_score`) == 1)
        self$`away_score` <- `away_score`
      }
    },
    toJSON = function() {
      GameSimResultsObject <- list()
      if (!is.null(self$`home_score`)) {
        GameSimResultsObject[['home_score']] <-
          self$`home_score`
      }
      if (!is.null(self$`away_score`)) {
        GameSimResultsObject[['away_score']] <-
          self$`away_score`
      }

      GameSimResultsObject
    },
    fromJSON = function(GameSimResultsJson) {
      GameSimResultsObject <- jsonlite::fromJSON(GameSimResultsJson)
      if (!is.null(GameSimResultsObject$`home_score`)) {
        self$`home_score` <- GameSimResultsObject$`home_score`
      }
      if (!is.null(GameSimResultsObject$`away_score`)) {
        self$`away_score` <- GameSimResultsObject$`away_score`
      }
      self
    },
    toJSONString = function() {
      jsoncontent <- c(
        if (!is.null(self$`home_score`)) {
        sprintf(
        '"home_score":
          %d
                ',
        self$`home_score`
        )},
        if (!is.null(self$`away_score`)) {
        sprintf(
        '"away_score":
          %d
                ',
        self$`away_score`
        )}
      )
      jsoncontent <- paste(jsoncontent, collapse = ",")
      paste('{', jsoncontent, '}', sep = "")
    },
    fromJSONString = function(GameSimResultsJson) {
      GameSimResultsObject <- jsonlite::fromJSON(GameSimResultsJson)
      self$`home_score` <- GameSimResultsObject$`home_score`
      self$`away_score` <- GameSimResultsObject$`away_score`
      self
    }
  )
)
singlearity-sports/singlearity-R documentation built on April 21, 2022, 3:48 a.m.