-
Notifications
You must be signed in to change notification settings - Fork 214
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds NumberToNearestIntegerConverter
- Loading branch information
Showing
2 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} | ||
} | ||
} |
68a189d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
spec ?