| Conditions | 1 |
| Paths | 1 |
| Total Lines | 135 |
| 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 | |||
| 5 | /** |
||
| 6 | * Information about the contents of a collection. |
||
| 7 | * |
||
| 8 | * @constructor |
||
| 9 | * @param {Object} [json] |
||
|
|
|||
| 10 | */ |
||
| 11 | var CollectionContent = function(json){ |
||
| 12 | |||
| 13 | // Protect against forgetting the new keyword when calling the constructor |
||
| 14 | if(!(this instanceof CollectionContent)){ |
||
| 15 | return new CollectionContent(json); |
||
| 16 | } |
||
| 17 | |||
| 18 | // If the given object is already an instance then just return it. DON'T copy it. |
||
| 19 | if(CollectionContent.isInstance(json)){ |
||
| 20 | return json; |
||
| 21 | } |
||
| 22 | |||
| 23 | this.init(json); |
||
| 24 | }; |
||
| 25 | |||
| 26 | CollectionContent.prototype = Object.create(GedcomX.ExtensibleData.prototype); |
||
| 27 | |||
| 28 | CollectionContent._gedxClass = CollectionContent.prototype._gedxClass = 'GedcomX.CollectionContent'; |
||
| 29 | |||
| 30 | CollectionContent.jsonProps = [ |
||
| 31 | 'resourceType', |
||
| 32 | 'count', |
||
| 33 | 'completeness' |
||
| 34 | ]; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * Check whether the given object is an instance of this class. |
||
| 38 | * |
||
| 39 | * @param {Object} obj |
||
| 40 | * @returns {Boolean} |
||
| 41 | */ |
||
| 42 | CollectionContent.isInstance = function(obj){ |
||
| 43 | return utils.isInstance(obj, this._gedxClass); |
||
| 44 | }; |
||
| 45 | |||
| 46 | /** |
||
| 47 | * Initialize from JSON |
||
| 48 | * |
||
| 49 | * @param {Object} |
||
| 50 | * @return {CollectionContent} this |
||
| 51 | */ |
||
| 52 | CollectionContent.prototype.init = function(json){ |
||
| 53 | |||
| 54 | GedcomX.ExtensibleData.prototype.init.call(this, json); |
||
| 55 | |||
| 56 | if(json){ |
||
| 57 | this.setResourceType(json.resourceType); |
||
| 58 | this.setCount(json.count); |
||
| 59 | this.setCompleteness(json.completeness); |
||
| 60 | } |
||
| 61 | return this; |
||
| 62 | }; |
||
| 63 | |||
| 64 | /** |
||
| 65 | * Set the resource type |
||
| 66 | * |
||
| 67 | * @param {String} resourceType |
||
| 68 | * @return {CollectionContent} this |
||
| 69 | */ |
||
| 70 | CollectionContent.prototype.setResourceType = function(resourceType){ |
||
| 71 | this.resourceType = resourceType; |
||
| 72 | return this; |
||
| 73 | }; |
||
| 74 | |||
| 75 | /** |
||
| 76 | * Get the resource type |
||
| 77 | * |
||
| 78 | * @return {String} resourceType |
||
| 79 | */ |
||
| 80 | CollectionContent.prototype.getResourceType = function(){ |
||
| 81 | return this.resourceType; |
||
| 82 | }; |
||
| 83 | |||
| 84 | /** |
||
| 85 | * Set the count |
||
| 86 | * |
||
| 87 | * @param {Integer} count |
||
| 88 | * @return {CollectionContent} this |
||
| 89 | */ |
||
| 90 | CollectionContent.prototype.setCount = function(count){ |
||
| 91 | this.count = count; |
||
| 92 | return this; |
||
| 93 | }; |
||
| 94 | |||
| 95 | /** |
||
| 96 | * Get the count |
||
| 97 | * |
||
| 98 | * @return {Integer} |
||
| 99 | */ |
||
| 100 | CollectionContent.prototype.getCount = function(){ |
||
| 101 | return this.count; |
||
| 102 | }; |
||
| 103 | |||
| 104 | /** |
||
| 105 | * Set the completeness |
||
| 106 | * |
||
| 107 | * @param {Number} completeness A number between 0 and 1 |
||
| 108 | * @return {CollectionContent} |
||
| 109 | */ |
||
| 110 | CollectionContent.prototype.setCompleteness = function(completeness){ |
||
| 111 | this.completeness = completeness; |
||
| 112 | return this; |
||
| 113 | }; |
||
| 114 | |||
| 115 | /** |
||
| 116 | * Get the completeness |
||
| 117 | * |
||
| 118 | * @return {Number} completeness |
||
| 119 | */ |
||
| 120 | CollectionContent.prototype.getCompleteness = function(){ |
||
| 121 | return this.completeness; |
||
| 122 | }; |
||
| 123 | |||
| 124 | /** |
||
| 125 | * Export the object as JSON |
||
| 126 | * |
||
| 127 | * @return {Object} JSON object |
||
| 128 | */ |
||
| 129 | CollectionContent.prototype.toJSON = function(){ |
||
| 130 | return this._toJSON(GedcomX.ExtensibleData, CollectionContent.jsonProps); |
||
| 131 | }; |
||
| 132 | |||
| 133 | GedcomX.CollectionContent = CollectionContent; |
||
| 134 | |||
| 135 | }; |