// Generated by CoffeeScript 1.12.6

/*
 * Modular spec parsing helpers
 */

(function() {
  'use strict';
  var object;

  object = require('../common/object');

  module.exports = {
    applyHarnessScope: function(dd, params) {
      var harness, harnessScope, scope;
      harnessScope = params.harness;
      if (!(harnessScope && typeof harnessScope === 'object')) {
        return params;
      }
      for (harness in harnessScope) {
        scope = harnessScope[harness];
        if (dd.harness.split(harness).length > 1) {
          params = object.merge(params, scope);
        }
      }
      return params;
    },
    filterHash: function(hash, keys) {
      var filtered, hashKey, hashKeys, i, len;
      if (!keys.length) {
        return hash;
      }
      hashKeys = Object.keys(hash);
      filtered = {};
      for (i = 0, len = hashKeys.length; i < len; i++) {
        hashKey = hashKeys[i];
        if ((hash[hashKey] != null) && object.match(hashKey, keys)) {
          filtered[hashKey] = hash[hashKey];
        }
      }
      return filtered;
    },
    getFilteredList: function(filesHash, params) {
      var list;
      list = Object.keys(filesHash);
      if (!(params && typeof params === 'object')) {
        return list;
      }
      params.only = object.toArray(params.only);
      list = Object.keys(this.filterHash(filesHash, params.only));
      params.except = object.toArray(params.except, 'string');
      if (!Array.isArray(params.except)) {
        return list;
      }
      return list.filter(function(name) {
        return !object.match(name, params.except);
      });
    },
    parseSharedSpecs: function(filesHash, params) {
      var i, j, len, len1, module, moduleName, moduleNames, modulePath, ref, sharedSpecFolder, sharingModules, specPaths;
      moduleNames = Object.keys(filesHash);
      specPaths = {};
      for (i = 0, len = moduleNames.length; i < len; i++) {
        moduleName = moduleNames[i];
        modulePath = moduleName.split('.').join('/');
        specPaths[moduleName] = params.spec + "/" + modulePath;
      }
      if (!(params.shareSpecs && typeof params.shareSpecs === 'object')) {
        return specPaths;
      }
      ref = params.shareSpecs;
      for (sharedSpecFolder in ref) {
        sharingModules = ref[sharedSpecFolder];
        for (j = 0, len1 = sharingModules.length; j < len1; j++) {
          module = sharingModules[j];
          if (typeof specPaths[module] === 'string') {
            specPaths[module] = params.spec + "/" + sharedSpecFolder;
          }
        }
      }
      return specPaths;
    }
  };

}).call(this);
