Pre-release
AdventureJS Docs Downloads
Score: 0 Moves: 0
// getName.js
(function () {
  /* global AdventureJS A */
  var p = AdventureJS.Assets.Asset.prototype;

  /**
   * <strong>getName</strong> is called to remove an asset
   * from the game world.
   * @memberOf AdventureJS.Assets.Asset
   * @method AdventureJS.Assets.Asset#getName
   * @param {String} type The type of name to get. Valid options are: article, definite|the, indefinite|a, fungible? (with question mark). Provide values in lowercase, Sentencecase or UPPERCASE to get results in that format.
   * @param {String} kace Optionally provide an explicit case, which takes precedence over cases found in type param. Valid options are: lower, upper, capitalize, proper.
   */
  p.getName = function Asset_getName(type = "article", kace = "") {
    if (kace === "lower") type = type.toLowerCase();
    if (kace === "upper") type = type.toUpperCase();
    if (kace === "capitalize") type = A.FX.capitalize(type);
    if (kace === "proper") type = A.FX.propercase(type);

    switch (type) {
      case "article":
        return this.article_name;
      case "Article":
        return this.Article_name;
      case "ARTICLE":
        return this.ARTICLE_NAME;

      case "definite":
      case "the":
        return this.definite_name;
      case "Definite":
      case "The":
        return this.Definite_name;
      case "DEFINITE":
      case "THE":
        return this.DEFINITE_NAME;

      case "indefinite":
      case "a":
        return this.indefinite_name;
      case "Indefinite":
      case "A":
        return this.Indefinite_name;
      case "INDEFINITE":
        return this.INDEFINITE_NAME;

      case "fungible?":
        return this.is.fungible ? this.indefinite_name : this.article_name;
      case "Fungible?":
        return this.is.fungible ? this.Indefinite_name : this.Article_name;
      case "FUNGIBLE?":
        return this.is.fungible ? this.INDEFINITE_NAME : this.ARTICLE_NAME;
    }

    return this.name;
  };
})();