R/ISORepresentativeFraction.R

#' ISORepresentativeFraction
#'
#' @docType class
#' @importFrom R6 R6Class
#' @export
#' @keywords ISO representative fraction
#' @return Object of \code{\link{R6Class}} for modelling an ISO RepresentativeFraction
#' @format \code{\link{R6Class}} object.
#' 
#' @examples 
#'   fr <- ISORepresentativeFraction$new(denominator = 1L)
#'   xml1 <- fr$encode()
#'   fr$setDenominator(2L)
#'   xml2 <- fr$encode()
#'   
#' @references 
#'   ISO 19115:2003 - Geographic information -- Metadata
#'  
#' @author Emmanuel Blondel <emmanuel.blondel1@@gmail.com>
#'
ISORepresentativeFraction <- R6Class("ISORepresentativeFraction",
  inherit = ISOAbstractObject,
  private = list(
    xmlElement = "MD_RepresentativeFraction",
    xmlNamespacePrefix = "GMD"
  ),
  public = list(
    #'@field denominator denominator
    denominator = NULL,
    
    #'@description Initializes object
    #'@param xml object of class \link{XMLInternalNode-class}
    #'@param denominator denominator
    initialize = function(xml = NULL, denominator){
      super$initialize(xml = xml)
      if(is.null(xml) & !missing(denominator)){
        self$setDenominator(denominator)
      }
    },
    
    #'@description Set denominator
    #'@param denominator object of class \link{integer}
    setDenominator = function(denominator){
      newValue <- denominator
      if(!is(denominator, "numeric")){
        newValue <- as.numeric(denominator)
        if(is.na(newValue)){
          stop(sprintf("Value '%s' cannot be coerced to 'numeric'", denominator))
        }
      }
      self$denominator = newValue
    }
  )                        
)
eblondel/geometa documentation built on May 3, 2024, 7:55 p.m.