LCOV - code coverage report
Current view: top level - simulation/helpers - Resources.js (source / functions) Hit Total Coverage
Test: lcov.info Lines: 0 27 0.0 %
Date: 2023-04-02 12:52:40 Functions: 0 4 0.0 %

          Line data    Source code
       1             : /**
       2             :  * Builds a RelaxRNG schema based on currently valid elements.
       3             :  *
       4             :  * To prevent validation errors, disabled resources are included in the schema.
       5             :  *
       6             :  * @param datatype - The datatype of the element
       7             :  * @param additional - Array of additional data elements. Time, xp, etc.
       8             :  * @param subtypes - If true, resource subtypes will be included as well.
       9             :  * @return RelaxNG schema string
      10             :  */
      11           0 : Resources.prototype.BuildSchema = function(datatype, additional = [], subtypes = false)
      12             : {
      13           0 :         if (!datatype)
      14           0 :                 return "";
      15             : 
      16           0 :         switch (datatype)
      17             :         {
      18             :         case "decimal":
      19             :         case "nonNegativeDecimal":
      20             :         case "positiveDecimal":
      21           0 :                 datatype = "<ref name='" + datatype + "'/>";
      22           0 :                 break;
      23             : 
      24             :         default:
      25           0 :                 datatype = "<data type='" + datatype + "'/>";
      26             :         }
      27             : 
      28           0 :         let resCodes = this.resourceData.map(resource => resource.code);
      29           0 :         let schema = "";
      30           0 :         for (let res of resCodes.concat(additional))
      31           0 :                 schema +=
      32             :                         "<optional>" +
      33             :                                 "<element name='" + res + "'>" +
      34             :                                         datatype +
      35             :                                 "</element>" +
      36             :                         "</optional>";
      37             : 
      38           0 :         if (!subtypes)
      39           0 :                 return "<interleave>" + schema + "</interleave>";
      40             : 
      41           0 :         for (let res of this.resourceData)
      42           0 :                 for (let subtype in res.subtypes)
      43           0 :                         schema +=
      44             :                                 "<optional>" +
      45             :                                         "<element name='" + res.code + "." + subtype + "'>" +
      46             :                                                 datatype +
      47             :                                         "</element>" +
      48             :                                 "</optional>";
      49             : 
      50           0 :         return "<interleave>" + schema + "</interleave>";
      51             : };
      52             : 
      53             : /**
      54             :  * Builds the value choices for a RelaxNG `<choice></choice>` object, based on currently valid resources.
      55             :  *
      56             :  * @oaram subtypes - If set to true, the choices returned will be resource subtypes, rather than main types
      57             :  * @return String of RelaxNG Schema `<choice/>` values.
      58             :  */
      59           0 : Resources.prototype.BuildChoicesSchema = function(subtypes = false)
      60             : {
      61           0 :         let schema = "";
      62             : 
      63           0 :         if (!subtypes)
      64           0 :                 for (let res of this.resourceData.map(resource => resource.code))
      65           0 :                         schema += "<value>" + res + "</value>";
      66             :         else
      67           0 :                 for (let res of this.resourceData)
      68           0 :                         for (let subtype in res.subtypes)
      69           0 :                                 schema += "<value>" + res.code + "." + subtype + "</value>";
      70             : 
      71           0 :         return "<choice>" + schema + "</choice>";
      72             : };
      73             : 
      74           0 : Resources = new Resources();

Generated by: LCOV version 1.14