| 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 | * Information about a category associated with an atom entry or feed. |
||
| 8 | * |
||
| 9 | * @constructor |
||
| 10 | * @param {Object} [json] |
||
|
|
|||
| 11 | */ |
||
| 12 | var AtomCategory = function(json){ |
||
| 13 | |||
| 14 | // Protect against forgetting the new keyword when calling the constructor |
||
| 15 | if(!(this instanceof AtomCategory)){ |
||
| 16 | return new AtomCategory(json); |
||
| 17 | } |
||
| 18 | |||
| 19 | // If the given object is already an instance then just return it. DON'T copy it. |
||
| 20 | if(AtomCategory.isInstance(json)){ |
||
| 21 | return json; |
||
| 22 | } |
||
| 23 | |||
| 24 | this.init(json); |
||
| 25 | }; |
||
| 26 | |||
| 27 | AtomCategory.prototype = Object.create(AtomCommon.prototype); |
||
| 28 | |||
| 29 | AtomCategory._gedxClass = AtomCategory.prototype._gedxClass = 'GedcomX.AtomCategory'; |
||
| 30 | |||
| 31 | AtomCategory.jsonProps = [ |
||
| 32 | 'scheme', |
||
| 33 | 'term', |
||
| 34 | 'label' |
||
| 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 | AtomCategory.isInstance = function(obj){ |
||
| 44 | return utils.isInstance(obj, this._gedxClass); |
||
| 45 | }; |
||
| 46 | |||
| 47 | /** |
||
| 48 | * Initialize from JSON |
||
| 49 | * |
||
| 50 | * @param {Object} |
||
| 51 | * @return {AtomCategory} this |
||
| 52 | */ |
||
| 53 | AtomCategory.prototype.init = function(json){ |
||
| 54 | |||
| 55 | AtomCommon.prototype.init.call(this, json); |
||
| 56 | |||
| 57 | if(json){ |
||
| 58 | this.setScheme(json.scheme); |
||
| 59 | this.setTerm(json.term); |
||
| 60 | this.setLabel(json.label); |
||
| 61 | } |
||
| 62 | return this; |
||
| 63 | }; |
||
| 64 | |||
| 65 | /** |
||
| 66 | * Set the scheme |
||
| 67 | * |
||
| 68 | * @param {String} scheme |
||
| 69 | * @return {AtomCategory} this |
||
| 70 | */ |
||
| 71 | AtomCategory.prototype.setScheme = function(scheme){ |
||
| 72 | this.scheme = scheme; |
||
| 73 | return this; |
||
| 74 | }; |
||
| 75 | |||
| 76 | /** |
||
| 77 | * Get the scheme |
||
| 78 | * |
||
| 79 | * @return {AtomCategory} this |
||
| 80 | */ |
||
| 81 | AtomCategory.prototype.getScheme = function(){ |
||
| 82 | return this.scheme; |
||
| 83 | }; |
||
| 84 | |||
| 85 | /** |
||
| 86 | * Set the term |
||
| 87 | * |
||
| 88 | * @param {String} term |
||
| 89 | * @return {AtomCategory} this |
||
| 90 | */ |
||
| 91 | AtomCategory.prototype.setTerm = function(term){ |
||
| 92 | this.term = term; |
||
| 93 | return this; |
||
| 94 | }; |
||
| 95 | |||
| 96 | /** |
||
| 97 | * Get the term |
||
| 98 | * |
||
| 99 | * @return {AtomCategory} this |
||
| 100 | */ |
||
| 101 | AtomCategory.prototype.getTerm = function(){ |
||
| 102 | return this.term; |
||
| 103 | }; |
||
| 104 | |||
| 105 | /** |
||
| 106 | * Set the label |
||
| 107 | * |
||
| 108 | * @param {String} label |
||
| 109 | * @return {AtomCategory} this |
||
| 110 | */ |
||
| 111 | AtomCategory.prototype.setLabel = function(label){ |
||
| 112 | this.label = label; |
||
| 113 | return this; |
||
| 114 | }; |
||
| 115 | |||
| 116 | /** |
||
| 117 | * Get the label |
||
| 118 | * |
||
| 119 | * @return {AtomCategory} this |
||
| 120 | */ |
||
| 121 | AtomCategory.prototype.getLabel = function(){ |
||
| 122 | return this.label; |
||
| 123 | }; |
||
| 124 | |||
| 125 | /** |
||
| 126 | * Export the object as JSON |
||
| 127 | * |
||
| 128 | * @return {Object} JSON object |
||
| 129 | */ |
||
| 130 | AtomCategory.prototype.toJSON = function(){ |
||
| 131 | return this._toJSON(AtomCommon, AtomCategory.jsonProps); |
||
| 132 | }; |
||
| 133 | |||
| 134 | GedcomX.AtomCategory = AtomCategory; |
||
| 135 | |||
| 136 | }; |