Skip to content

Commit

Permalink
Adds NumberToNearestIntegerConverter
Browse files Browse the repository at this point in the history
  • Loading branch information
marchant committed Sep 18, 2017
1 parent 61ee9c4 commit 68a189d
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
52 changes: 52 additions & 0 deletions core/converter/number-to-nearest-integer-converter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* @module montage/core/converter/number-to-nearest-integer-converter
* @requires montage/core/converter/converter
*/
var Converter = require("./converter").Converter,
singleton;

/**
* Converts a number to an integer
* @class NumberToNearestIntegerConverter
* @extends Converter
*/
var NumberToNearestIntegerConverter = exports.NumberToNearestIntegerConverter = Converter.specialize({

constructor: {
value: function () {
if (this.constructor === NumberToNearestIntegerConverter) {
if (!singleton) {
singleton = this;
}

return singleton;
}

return this;
}
},

convert: {
value: function(value) {
return Math.round(value);
}
},

revert: {
value: function(value) {
return Math.round(value);
}
}


});

Object.defineProperty(exports, 'singleton', {
get: function () {
if (!singleton) {
singleton = new NumberToNearestIntegerConverter();
}

return singleton;
}
});
25 changes: 25 additions & 0 deletions core/converter/number-to-nearest-integer-converter.mjson
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"converter_descriptor": {
"object": "core/converter/converter.mjson"
},
"root": {
"prototype": "core/meta/module-object-descriptor",
"values": {
"name": "NumberToNearestIntegerConverter",
"customPrototype": false,
"parent": {
"@": "converter_descriptor"
},
"propertyDescriptors": [],
"propertyDescriptorGroups": {},
"propertyValidationRules": {},
"objectDescriptorModule": {
"%": "core/converter/number-to-nearest-integer-converter.mjson"
},
"exportName": "NumberToNearestIntegerConverter",
"module": {
"%": "core/converter/number-to-nearest-integer-converter"
}
}
}
}

1 comment on commit 68a189d

@hthetiot
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spec ?

Please sign in to comment.