Name

sn_cmdb_int_util.CmdbIntegrationCompanyModelUtil

Description

Utility class to cleanse Company names

Script

var CmdbIntegrationCompanyModelUtil = Class.create();
CmdbIntegrationCompanyModelUtil.prototype = {
  initialize: function() {
  	this.maxCompanyNameSize = 80;
  },

  cleanseCompany: function(company) {
      if (gs.nil(company))
          return null;

      company = this.removeTradeMark(company);
      company = this.removeSpecialCases(company);
      company = this.removeCompanySuffix(company);
      company = this.trimToOutOfBoxMaxLength(company);
      return company.trim();
  },

  removeCompanySuffix: function(company) {
      var lastIndex = function(company) {
          return company.lastIndexOf(" ");
      };
      var lastChar = function(company) {
          return company.length - 1;
      };

      var complete = false;
      while (!complete) {
          var companyLowerCase = company.toLowerCase();
          var seen = false;
          [
              {endsWith: ".",             action: lastChar},
              {endsWith: " corporation",  action: lastIndex},
              {endsWith: " corp",         action: lastIndex},
              {endsWith: " inc",          action: lastIndex},
              {endsWith: " ltd",          action: lastIndex},
              {endsWith: ",",             action: lastChar},
              {endsWith: " incorporated", action: lastIndex}
          ].forEach(function(obj) {
              if (companyLowerCase.endsWith(obj.endsWith)) {
                  company = company.substring(0, obj.action(company));
                  companyLowerCase = company.toLowerCase();
                  seen = true;
              }
          });
          if (!seen)
              complete = true;
      }
      return company;
  },

  removeSpecialCases: function(company) {
      // strip off genuine, its just intel
      if (company.toLowerCase().includes("genuineintel"))
          company = "Intel";

      // strip off computer if its dell
      if (company.toLowerCase().includes("dell computer"))
          company = "Dell Inc.";
      return company;
  },

  removeTradeMark: function(company) {
      ["(R)", "®", "™", "(TM)"].forEach(function(value) {
          company = company.replace(value, "");
      });
      return company;
  },

  removeLanguage: function(name) {
      var self = this;
      ["(remove only)", "(english)", "[english]"].forEach(function(value) {
          name = self.deleteTrailing(name, value);
      });
      return name;
  },
  
  setMaxCompanyNameSize: function(size) {
  	if (gs.nil(size) || isNaN(size))
  		return;
  	
  	this.maxCompanyNameSize = size;
  },

  trimToOutOfBoxMaxLength: function(company) {
      if (gs.nil(company))
          return company;

      if (company.length > this.maxCompanyNameSize)
          return company.substring(0, this.maxCompanyNameSize);

      return company;
  },
  
  deleteTrailing: function(str, trailing) {
      if (!str || !trailing)
          return str;
      if (str.length <= trailing.length)
          return str;
  	
      //str does not end with trailing
      if (str.indexOf(trailing, str.length - trailing.length) == -1)
          return str;
      return str.substring(0, str.length - trailing.length);
  },

  type: 'CmdbIntegrationCompanyModelUtil'
};

Sys ID

72a1bc4fc71a00109cea1197fdc260cc

Offical Documentation

Official Docs: