var quantify      = require('./quantifier');
var _escapeRegExp = require('./escaper').escapeRegExp;
var _translate    = require('./specialIdentifiers').translate;


var interpret = function(userArguments) {
    switch (userArguments.length) {
        case 2:
            return _makeNumberedConstraint(userArguments[0], userArguments[1]);
        case 1:
            return _makePatternedConstraint(userArguments[0]);
        default:
            throw new Error('interpret: wrong number of arguments: got ' + userArguments.length + ', expected 1 or 2');
    }
};

var _makeNumberedConstraint = function(count, type) {
    return quantify.exactly(_makePatternedConstraint(type), count);
};

var _makePatternedConstraint = function(pattern) {
    return _translate(_escapeRegExp(pattern));
};



module.exports = {
    interpret: interpret
};

var quantify      = require('./quantifier');
var _escapeRegExp = require('./escaper').escapeRegExp;
var _translate    = require('./specialIdentifiers').translate;


var interpret = function(userArguments) {
    return constraintBuilderFromArgCount[userArguments.length].apply(null, userArguments);
};


var _buildNumberedConstraint = function(count, type) {
    return quantify.exactly(_buildPatternedConstraint(type), count);
};

var _buildPatternedConstraint = function(pattern) {
    return _translate(_escapeRegExp(pattern));
};

var constraintBuilderFromArgCount = {
    1: _buildPatternedConstraint,
    2: _buildNumberedConstraint
};

module.exports = {
    interpret: interpret
};

Replace switch statement with an object literal.
Replace switch statement with an object literal.

Technically, there is little difference because a lookup is going to have to happen
anyway, but I believe this option is cleaner and shorter.

This commit also removes the exception being thrown in the default case. Now, a different
exception will be thrown in the default case (the engine will attempt to call 'undefined'),
but this case is not hardcoded in the code because, again, that usage isn't documented
in the spec, so it shouldn't be used in the first place.
