quixote
Version:
CSS unit and integration testing
44 lines (33 loc) • 1.31 kB
JavaScript
// Copyright (c) 2014 Titanium I.T. LLC. All rights reserved. For license, see "README" or "LICENSE" file.
;
var ensure = require("../util/ensure.js");
var PositionDescriptor = require("./position_descriptor.js");
var X_DIMENSION = "x";
var Y_DIMENSION = "y";
var Me = module.exports = function Center(dimension, position1, position2, description) {
ensure.signature(arguments, [ String, PositionDescriptor, PositionDescriptor, String ]);
this.should = this.createShould();
if (dimension === X_DIMENSION) PositionDescriptor.x(this);
else if (dimension === Y_DIMENSION) PositionDescriptor.y(this);
else ensure.unreachable("Unknown dimension: " + dimension);
this._dimension = dimension;
this._position1 = position1;
this._position2 = position2;
this._description = description;
};
PositionDescriptor.extend(Me);
Me.x = factoryFn(X_DIMENSION);
Me.y = factoryFn(Y_DIMENSION);
Me.prototype.value = function value() {
ensure.signature(arguments, []);
return this._position1.value().midpoint(this._position2.value());
};
Me.prototype.toString = function toString() {
ensure.signature(arguments, []);
return this._description;
};
function factoryFn(dimension) {
return function(position1, position2, description) {
return new Me(dimension, position1, position2, description);
};
}