Permalink
Browse files

[api] Added versioning for device

  • Loading branch information...
1 parent ff74860 commit 49e953295419f47ecdc5ab157ebddeda98c7a076 @3rd-Eden committed Jan 9, 2013
Showing with 53 additions and 3 deletions.
  1. +53 −3 index.js
View
@@ -289,18 +289,65 @@ OperatingSystem.prototype.toJSON = function toJSON(){
* @param {String} family The name of the os
* @api public
*/
-function Device(family) {
+function Device(family, major, minor, patch) {
this.family = family || 'Other';
+ this.major = major || '';
+ this.minor = minor || '';
+ this.patch = patch || '';
}
/**
+ * Generates a stringified version of the Device.
+ *
+ * @returns {String} "Device 0.0.0"
+ * @api public
+ */
+Device.prototype.toString = function toString() {
+ var output = this.family
+ , version = this.toVersion();
+
+ if (version) output += ' '+ version;
+ return output;
+};
+
+/**
+ * Generates the version of the Device.
+ *
+ * @returns {String}
+ * @api public
+ */
+Device.prototype.toVersion = function toVersion() {
+ var version = '';
+
+ if (this.major) {
+ version += this.major;
+
+ if (this.minor) {
+ version += '.' + this.minor;
+
+ // Special case here, the patch can also be Alpha, Beta etc so we need
+ // to check if it's a string or not.
+ if (this.patch) {
+ version += (isNaN(+this.patch) ? ' ' : '.') + this.patch;
+ }
+ }
+ }
+
+ return version;
+};
+
+/**
* Get string representation.
*
* @returns {String}
* @api public
*/
Device.prototype.toString = function toString() {
- return this.family;
+ var output = this.family
+ , version = this.toVersion();
+
+ if (version) output += ' '+ version;
+ return output;
};
/**
@@ -312,7 +359,10 @@ Device.prototype.toString = function toString() {
*/
Device.prototype.toJSON = function toJSON() {
return {
- family: this.family
+ family: this.family
+ , major: this.major || undefined
+ , minor: this.minor || undefined
+ , patch: this.patch || undefined
};
};

0 comments on commit 49e9532

Please sign in to comment.