1
|
|
|
var ExtensibleData = require('./ExtensibleData'), |
2
|
|
|
GDate = require('./Date'), |
3
|
|
|
PlaceReference = require('./PlaceReference'), |
4
|
|
|
utils = require('./utils'); |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* A description of the spatial and temporal coverage of a resource. |
8
|
|
|
* |
9
|
|
|
* @constructor |
10
|
|
|
* @apram {Object} [json] |
11
|
|
|
*/ |
12
|
|
|
var Coverage = function(json){ |
13
|
|
|
|
14
|
|
|
// Protect against forgetting the new keyword when calling the constructor |
15
|
|
|
if(!(this instanceof Coverage)){ |
16
|
|
|
return new Coverage(json); |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
// If the given object is already an instance then just return it. DON'T copy it. |
20
|
|
|
if(Coverage.isInstance(json)){ |
21
|
|
|
return json; |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
ExtensibleData.call(this, json); |
25
|
|
|
|
26
|
|
|
if(json){ |
|
|
|
|
27
|
|
|
this.setSpatial(json.spatial); |
28
|
|
|
this.setTemporal(json.temporal); |
|
|
|
|
29
|
|
|
} |
30
|
|
|
}; |
31
|
|
|
|
32
|
|
|
Coverage.prototype = Object.create(ExtensibleData.prototype); |
33
|
|
|
|
34
|
|
|
Coverage._gedxClass = Coverage.prototype._gedxClass = 'GedcomX.Coverage'; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Check whether the given object is an instance of this class. |
38
|
|
|
* |
39
|
|
|
* @param {Object} obj |
40
|
|
|
* @returns {Boolean} |
41
|
|
|
*/ |
42
|
|
|
Coverage.isInstance = function(obj){ |
43
|
|
|
return utils.isInstance(obj, this._gedxClass); |
44
|
|
|
}; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Get the spatial coverage |
48
|
|
|
* |
49
|
|
|
* @returns {PlaceReference} |
50
|
|
|
*/ |
51
|
|
|
Coverage.prototype.getSpatial = function(){ |
52
|
|
|
return this.spatial; |
53
|
|
|
}; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Set the spatial coverage |
57
|
|
|
* |
58
|
|
|
* @param {PlaceReference} spatial |
59
|
|
|
* @returns {Coverage} |
60
|
|
|
*/ |
61
|
|
|
Coverage.prototype.setSpatial = function(spatial){ |
62
|
|
|
if(spatial){ |
63
|
|
|
this.spatial = PlaceReference(spatial); |
64
|
|
|
} |
65
|
|
|
return this; |
66
|
|
|
}; |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Get the temporal coverage |
70
|
|
|
* |
71
|
|
|
* @returns {Date} |
72
|
|
|
*/ |
73
|
|
|
Coverage.prototype.getTemporal = function(){ |
74
|
|
|
return this.temporal; |
75
|
|
|
}; |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Set the temporal coverage |
79
|
|
|
* |
80
|
|
|
* @param {Date} temporal |
81
|
|
|
* @returns {Coverage} |
82
|
|
|
*/ |
83
|
|
|
Coverage.prototype.setTemporal = function(temporal){ |
84
|
|
|
if(temporal){ |
85
|
|
|
this.temporal = GDate(temporal); |
86
|
|
|
} |
87
|
|
|
return this; |
88
|
|
|
}; |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Export the object as JSON |
92
|
|
|
* |
93
|
|
|
* @return {Object} JSON object |
94
|
|
|
*/ |
95
|
|
|
Coverage.prototype.toJSON = function(){ |
96
|
|
|
var json = ExtensibleData.prototype.toJSON.call(this); |
97
|
|
|
|
98
|
|
|
if(this.spatial){ |
99
|
|
|
json.spatial = this.spatial.toJSON(); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
if(this.temporal){ |
103
|
|
|
json.temporal = this.temporal.toJSON(); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
return json; |
107
|
|
|
}; |
108
|
|
|
|
109
|
|
|
module.exports = Coverage; |
This check looks for functions where a
return
statement is found in some execution paths, but not in all.Consider this little piece of code
The function
isBig
will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly returnundefined
.This behaviour may not be what you had intended. In any case, you can add a
return undefined
to the other execution path to make the return value explicit.