Skip to content

Commit

Permalink
#181 support M3 - refactor codelist item value print method + fix Lan…
Browse files Browse the repository at this point in the history
…guage handling
  • Loading branch information
eblondel committed Oct 7, 2024
1 parent 728a0ec commit fdabdce
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
9 changes: 8 additions & 1 deletion R/ISOAbstractObject.R
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,16 @@ ISOAbstractObject <- R6Class("ISOAbstractObject",
if(!inherits(self, "GMLElement") && !inherits(self, "SWEElement")) cat(crayon::white(paste0("<", crayon::underline(self$getClassName()), ">")))
if(is(self, "ISOCodeListValue")){
clVal <- self$printAttrs$codeListValue
clDes <- self$codelistId$entries[self$codelistId$entries$value == clVal,"description"]
if("value" %in% names(clVal)) clVal = clVal$value
clDes <- self$codelistId$codeEntry[sapply(self$codelistId$codeEntry, function(ce){
id = ce$identifier
if("value" %in% names(id)) id = id$value
return(id == clVal)
})]
if(length(clDes)==0){
clDes <- self$valueDescription
}else{
clDes <- clDes[[1]]$description
}
cat(paste0(": ", clVal, if(add_codelist_description) crayon::cyan(paste0(" {",clDes,"}")) else ""))
}
Expand Down
6 changes: 5 additions & 1 deletion R/ISOCodeListValue.R
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@ ISOCodeListValue <- R6Class("ISOCodeListValue",

if(length(cl$codeEntry)>0){
if(!is.null(value)){
clEntry <- cl$codeEntry[sapply(cl$codeEntry, function(x){x$identifier == value})]
clEntry <- cl$codeEntry[sapply(cl$codeEntry, function(x){
id = x$identifier
if("value" %in% names(id)) id = id$value
return(id == value)
})]
if(length(clEntry)==0){
warning(sprintf("No ISO '%s' codelist entry for value '%s'", id, value))
clValue <- value
Expand Down
10 changes: 5 additions & 5 deletions R/ISOCodelist.R
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@ ISOCodelist <- R6Class("ISOCodelist",
codeEntry <- utils::read.csv(clFile, sep="|", stringsAsFactors = FALSE)
codeEntry <- codeEntry[,c("alpha3", "english", "english")]
colnames(codeEntry) <- c("value","name", "description")
# self$codeEntry = lapply(1:nrow(codeEntry), function(i){
# clv = ISOCodelistValue$new()
# clv$identifier = codeEntry[i,]$value; clv$description = codeEntry[i,]$description;
# return(clv)
# })
self$codeEntry = lapply(1:nrow(codeEntry), function(i){
clv = ISOCodelistValue$new()
clv$identifier = codeEntry[i,]$value; clv$description = codeEntry[i,]$description
return(clv)
})
}else{

isML <- regexpr("ML", refFile) > 0
Expand Down

0 comments on commit fdabdce

Please sign in to comment.