| Conditions | 1 |
| Paths | 1 |
| Total Lines | 136 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | module.exports = function(GedcomX){ |
||
| 2 | |||
| 3 | var utils = require('../utils'), |
||
| 4 | AtomCommon = require('./AtomCommon'); |
||
| 5 | |||
| 6 | /** |
||
| 7 | * The agent used to generate a feed |
||
| 8 | * |
||
| 9 | * @constructor |
||
| 10 | * @param {Object} [json] |
||
|
|
|||
| 11 | */ |
||
| 12 | var AtomGenerator = function(json){ |
||
| 13 | |||
| 14 | // Protect against forgetting the new keyword when calling the constructor |
||
| 15 | if(!(this instanceof AtomGenerator)){ |
||
| 16 | return new AtomGenerator(json); |
||
| 17 | } |
||
| 18 | |||
| 19 | // If the given object is already an instance then just return it. DON'T copy it. |
||
| 20 | if(AtomGenerator.isInstance(json)){ |
||
| 21 | return json; |
||
| 22 | } |
||
| 23 | |||
| 24 | this.init(json); |
||
| 25 | }; |
||
| 26 | |||
| 27 | AtomGenerator.prototype = Object.create(AtomCommon.prototype); |
||
| 28 | |||
| 29 | AtomGenerator._gedxClass = AtomGenerator.prototype._gedxClass = 'GedcomX.AtomGenerator'; |
||
| 30 | |||
| 31 | AtomGenerator.jsonProps = [ |
||
| 32 | 'uri', |
||
| 33 | 'version', |
||
| 34 | 'value' |
||
| 35 | ]; |
||
| 36 | |||
| 37 | /** |
||
| 38 | * Check whether the given object is an instance of this class. |
||
| 39 | * |
||
| 40 | * @param {Object} obj |
||
| 41 | * @returns {Boolean} |
||
| 42 | */ |
||
| 43 | AtomGenerator.isInstance = function(obj){ |
||
| 44 | return utils.isInstance(obj, this._gedxClass); |
||
| 45 | }; |
||
| 46 | |||
| 47 | /** |
||
| 48 | * Initialize from JSON |
||
| 49 | * |
||
| 50 | * @param {Object} |
||
| 51 | * @return {AtomGenerator} this |
||
| 52 | */ |
||
| 53 | AtomGenerator.prototype.init = function(json){ |
||
| 54 | |||
| 55 | AtomCommon.prototype.init.call(this, json); |
||
| 56 | |||
| 57 | if(json){ |
||
| 58 | this.setUri(json.uri); |
||
| 59 | this.setVersion(json.version); |
||
| 60 | this.setValue(json.value); |
||
| 61 | } |
||
| 62 | return this; |
||
| 63 | }; |
||
| 64 | |||
| 65 | /** |
||
| 66 | * Set the uri |
||
| 67 | * |
||
| 68 | * @param {String} uri |
||
| 69 | * @return {AtomGenerator} this |
||
| 70 | */ |
||
| 71 | AtomGenerator.prototype.setUri = function(uri){ |
||
| 72 | this.uri = uri; |
||
| 73 | return this; |
||
| 74 | }; |
||
| 75 | |||
| 76 | /** |
||
| 77 | * Get the uri |
||
| 78 | * |
||
| 79 | * @return {String} this |
||
| 80 | */ |
||
| 81 | AtomGenerator.prototype.getUri = function(){ |
||
| 82 | return this.uri; |
||
| 83 | }; |
||
| 84 | |||
| 85 | /** |
||
| 86 | * Set the version |
||
| 87 | * |
||
| 88 | * @param {String} version |
||
| 89 | * @return {AtomGenerator} this |
||
| 90 | */ |
||
| 91 | AtomGenerator.prototype.setVersion = function(version){ |
||
| 92 | this.version = version; |
||
| 93 | return this; |
||
| 94 | }; |
||
| 95 | |||
| 96 | /** |
||
| 97 | * Get the version |
||
| 98 | * |
||
| 99 | * @return {String} this |
||
| 100 | */ |
||
| 101 | AtomGenerator.prototype.getVersion = function(){ |
||
| 102 | return this.version; |
||
| 103 | }; |
||
| 104 | |||
| 105 | /** |
||
| 106 | * Set the value |
||
| 107 | * |
||
| 108 | * @param {String} value |
||
| 109 | * @return {AtomGenerator} this |
||
| 110 | */ |
||
| 111 | AtomGenerator.prototype.setValue = function(value){ |
||
| 112 | this.value = value; |
||
| 113 | return this; |
||
| 114 | }; |
||
| 115 | |||
| 116 | /** |
||
| 117 | * Get the value |
||
| 118 | * |
||
| 119 | * @return {String} this |
||
| 120 | */ |
||
| 121 | AtomGenerator.prototype.getValue = function(){ |
||
| 122 | return this.value; |
||
| 123 | }; |
||
| 124 | |||
| 125 | /** |
||
| 126 | * Export the object as JSON |
||
| 127 | * |
||
| 128 | * @return {Object} JSON object |
||
| 129 | */ |
||
| 130 | AtomGenerator.prototype.toJSON = function(){ |
||
| 131 | return this._toJSON(AtomCommon, AtomGenerator.jsonProps); |
||
| 132 | }; |
||
| 133 | |||
| 134 | GedcomX.AtomGenerator = AtomGenerator; |
||
| 135 | |||
| 136 | }; |