R/matchup.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 Matchup
#'
#' @description Matchup Class
#'
#' @format An \code{R6Class} generator object
#'
#' @field batter  \link{Player} 
#'
#' @field pitcher  \link{Player} 
#'
#' @field atmosphere  \link{Atmosphere} 
#'
#' @field state  \link{State} 
#'
#' @field date Date character [optional]
#'
#' @importFrom R6 R6Class
#' @importFrom jsonlite fromJSON toJSON
#' @export
Matchup <- R6::R6Class(
  'Matchup',
  public = list(
    `batter` = NULL,
    `pitcher` = NULL,
    `atmosphere` = NULL,
    `state` = NULL,
    `date` = NULL,
    initialize = function(
        `batter`, `pitcher`, `atmosphere`, `state`, `date`=NULL, ...
    ) {
      local.optional.var <- list(...)
      if (length(local.optional.var) > 0) {
        stop(paste("Unknown argument(s) in initialize of object Matchup:", paste(names(local.optional.var), collapse=", "), collapse=" "))
      }
      if (!missing(`batter`)) {
        stopifnot(R6::is.R6(`batter`))
        self$`batter` <- `batter`
      }
      if (!missing(`pitcher`)) {
        stopifnot(R6::is.R6(`pitcher`))
        self$`pitcher` <- `pitcher`
      }
      if (!missing(`atmosphere`)) {
        stopifnot(R6::is.R6(`atmosphere`))
        self$`atmosphere` <- `atmosphere`
      }
      if (!missing(`state`)) {
        stopifnot(R6::is.R6(`state`))
        self$`state` <- `state`
      }
      if (!is.null(`date`)) {
        stopifnot(is.character(`date`), length(`date`) == 1)
        self$`date` <- `date`
      }
    },
    toJSON = function() {
      MatchupObject <- list()
      if (!is.null(self$`batter`)) {
        MatchupObject[['batter']] <-
          self$`batter`$toJSON()
      }
      if (!is.null(self$`pitcher`)) {
        MatchupObject[['pitcher']] <-
          self$`pitcher`$toJSON()
      }
      if (!is.null(self$`atmosphere`)) {
        MatchupObject[['atmosphere']] <-
          self$`atmosphere`$toJSON()
      }
      if (!is.null(self$`state`)) {
        MatchupObject[['state']] <-
          self$`state`$toJSON()
      }
      if (!is.null(self$`date`)) {
        MatchupObject[['date']] <-
          self$`date`
      }

      MatchupObject
    },
    fromJSON = function(MatchupJson) {
      MatchupObject <- jsonlite::fromJSON(MatchupJson)
      if (!is.null(MatchupObject$`batter`)) {
        batterObject <- Player$new()
        batterObject$fromJSON(jsonlite::toJSON(MatchupObject$batter, auto_unbox = TRUE, digits = NA))
        self$`batter` <- batterObject
      }
      if (!is.null(MatchupObject$`pitcher`)) {
        pitcherObject <- Player$new()
        pitcherObject$fromJSON(jsonlite::toJSON(MatchupObject$pitcher, auto_unbox = TRUE, digits = NA))
        self$`pitcher` <- pitcherObject
      }
      if (!is.null(MatchupObject$`atmosphere`)) {
        atmosphereObject <- Atmosphere$new()
        atmosphereObject$fromJSON(jsonlite::toJSON(MatchupObject$atmosphere, auto_unbox = TRUE, digits = NA))
        self$`atmosphere` <- atmosphereObject
      }
      if (!is.null(MatchupObject$`state`)) {
        stateObject <- State$new()
        stateObject$fromJSON(jsonlite::toJSON(MatchupObject$state, auto_unbox = TRUE, digits = NA))
        self$`state` <- stateObject
      }
      if (!is.null(MatchupObject$`date`)) {
        self$`date` <- MatchupObject$`date`
      }
      self
    },
    toJSONString = function() {
      jsoncontent <- c(
        if (!is.null(self$`batter`)) {
        sprintf(
        '"batter":
        %s
        ',
        jsonlite::toJSON(self$`batter`$toJSON(), auto_unbox=TRUE, digits = NA)
        )},
        if (!is.null(self$`pitcher`)) {
        sprintf(
        '"pitcher":
        %s
        ',
        jsonlite::toJSON(self$`pitcher`$toJSON(), auto_unbox=TRUE, digits = NA)
        )},
        if (!is.null(self$`atmosphere`)) {
        sprintf(
        '"atmosphere":
        %s
        ',
        jsonlite::toJSON(self$`atmosphere`$toJSON(), auto_unbox=TRUE, digits = NA)
        )},
        if (!is.null(self$`state`)) {
        sprintf(
        '"state":
        %s
        ',
        jsonlite::toJSON(self$`state`$toJSON(), auto_unbox=TRUE, digits = NA)
        )},
        if (!is.null(self$`date`)) {
        sprintf(
        '"date":
          "%s"
                ',
        self$`date`
        )}
      )
      jsoncontent <- paste(jsoncontent, collapse = ",")
      paste('{', jsoncontent, '}', sep = "")
    },
    fromJSONString = function(MatchupJson) {
      MatchupObject <- jsonlite::fromJSON(MatchupJson)
      self$`batter` <- Player$new()$fromJSON(jsonlite::toJSON(MatchupObject$batter, auto_unbox = TRUE, digits = NA))
      self$`pitcher` <- Player$new()$fromJSON(jsonlite::toJSON(MatchupObject$pitcher, auto_unbox = TRUE, digits = NA))
      self$`atmosphere` <- Atmosphere$new()$fromJSON(jsonlite::toJSON(MatchupObject$atmosphere, auto_unbox = TRUE, digits = NA))
      self$`state` <- State$new()$fromJSON(jsonlite::toJSON(MatchupObject$state, auto_unbox = TRUE, digits = NA))
      self$`date` <- MatchupObject$`date`
      self
    }
  )
)
singlearity-sports/singlearity-R documentation built on April 21, 2022, 3:48 a.m.