dataschema-base.js revision 3cd3e1a007f7fd6874030808f97ef48e3a950b40
/**
* The DataSchema utility provides a common configurable interface for widgets to
* apply a given schema to a variety of data.
*
* @module dataschema
*/
var LANG = Y.Lang,
/**
* Base class for the YUI DataSchema utility.
* @class DataSchema.Base
* @static
*/
SchemaBase = {
/**
* Returns string name.
*
* @method toString
* @return {String} String representation for this object.
*/
toString: function() {
return "DataSchema.Base";
},
/**
* Overridable method returns data as-is.
*
* @method apply
* @param schema {Object} Schema to apply.
* @param data {Object} Data.
* @return {Object} Schema-parsed data.
* @static
*/
apply: function(schema, data) {
return data;
},
/**
* Applies field parser, if defined
*
* @method parse
* @param value {Object} Original value.
* @param field {Object} Field.
* @return {Object} Type-converted value.
*/
parse: function(value, field) {
if(field.parser) {
var parser = (LANG.isFunction(field.parser)) ?
field.parser : Y.Parsers[field.parser+''];
if(parser) {
value = parser.call(this, value);
}
}
return value;
}
};
Y.namespace("DataSchema").Base = SchemaBase;
Y.namespace("Parsers");