Code Duplication    Length = 128-178 lines in 2 locations

src/Fact.js 1 location

@@ 1-178 (lines=178) @@
1
var Conclusion = require('./Conclusion'),
2
    PlaceReference = require('./PlaceReference'),
3
    GDate = require('./Date'),
4
    Qualifier = require('./Qualifier'),
5
    utils = require('./utils');
6
7
/**
8
 * A fact for a person or relationship.
9
 * 
10
 * @constructor
11
 * @param {Object} [json]
12
 */
13
var Fact = function(json){
14
  
15
  // Protect against forgetting the new keyword when calling the constructor
16
  if(!(this instanceof Fact)){
17
    return new Fact(json);
18
  }
19
  
20
  // If the given object is already an instance then just return it. DON'T copy it.
21
  if(Fact.isInstance(json)){
22
    return json;
23
  }
24
  
25
  Conclusion.call(this, json);
26
  
27
  if(json){
28
    this.setType(json.type);
29
    this.setDate(json.date);
30
    this.setPlace(json.place);
31
    this.setValue(json.value);
32
    this.setQualifiers(json.qualifiers);
33
  }
34
};
35
36
Fact.prototype = Object.create(Conclusion.prototype);
37
38
Fact._gedxClass = Fact.prototype._gedxClass = 'GedcomX.Fact';
39
40
/**
41
 * Check whether the given object is an instance of this class.
42
 * 
43
 * @param {Object} obj
44
 * @returns {Boolean}
45
 */
46
Fact.isInstance = function(obj){
47
  return utils.isInstance(obj, this._gedxClass);
48
};
49
50
/**
51
 * Get the fact type
52
 * 
53
 * @returns {String} type
54
 */
55
Fact.prototype.getType = function(){
56
  return this.type;
57
};
58
59
/**
60
 * Set the fact type
61
 * 
62
 * @param {String} type
63
 * @returns {Fact} This instance
64
 */
65
Fact.prototype.setType = function(type){
66
  this.type = type;
67
  return this;
68
};
69
70
/**
71
 * Get the date
72
 * 
73
 * @returns {Date} date
74
 */
75
Fact.prototype.getDate = function(){
76
  return this.date;
77
};
78
79
/**
80
 * Set the date
81
 * 
82
 * @param {Date|Object} date
83
 * @returns {Fact} This instance
84
 */
85
Fact.prototype.setDate = function(date){
86
  if(date){
87
    this.date = GDate(date);
88
  }
89
  return this;
90
};
91
92
/**
93
 * Get the place reference
94
 * 
95
 * @returns {PlaceReference}
96
 */
97
Fact.prototype.getPlace = function(){
98
  return this.place;
99
};
100
101
/**
102
 * Set the place reference
103
 *
104
 * @param {PlaceReference|Object} place
105
 * @returns {Fact} This instance
106
 */
107
Fact.prototype.setPlace = function(place){
108
  if(place){
109
    this.place = PlaceReference(place);
110
  }
111
  return this;
112
};
113
114
/**
115
 * Get the value
116
 * 
117
 * @returns {String}
118
 */
119
Fact.prototype.getValue = function(){
120
  return this.value;
121
};
122
123
/**
124
 * Set the value
125
 * 
126
 * @param {String} value
127
 * @returns {Fact} This instance
128
 */
129
Fact.prototype.setValue = function(value){
130
  this.value = value;
131
  return this;
132
};
133
134
/**
135
 * Get qualifiers
136
 * 
137
 * @return {Qualifer[]}
138
 */
139
Fact.prototype.getQualifiers = function(){
140
  return this.qualifiers || [];
141
};
142
143
/**
144
 * Set the qualifiers
145
 * 
146
 * @param {Qualifer[]|Object[]} qualifiers
147
 * @returns {Fact} This instance
148
 */
149
Fact.prototype.setQualifiers = function(qualifiers){
150
  return this._setArray(qualifiers, 'qualifiers', 'addQualifier');
151
};
152
153
/**
154
 * Add a qualifier
155
 * 
156
 * @param {Qualifier|Object} qualifier
157
 * @returns {Fact} This instance
158
 */
159
Fact.prototype.addQualifier = function(qualifier){
160
  return this._arrayPush(qualifier, 'qualifiers', Qualifier);
161
};
162
163
/**
164
 * Export the object as JSON
165
 * 
166
 * @return {Object} JSON object
167
 */
168
Fact.prototype.toJSON = function(){
169
  return this._toJSON(Conclusion, [
170
    'type',
171
    'date',
172
    'place',
173
    'value',
174
    'qualifiers'
175
  ]);
176
};
177
178
module.exports = Fact;

src/NamePart.js 1 location

@@ 1-128 (lines=128) @@
1
var ExtensibleData = require('./ExtensibleData'),
2
    Qualifier = require('./Qualifier'),
3
    utils = require('./utils');
4
5
/**
6
 * A part of a name.
7
 * 
8
 * @constructor
9
 * @param {Object} [json]
10
 */
11
var NamePart = function(json){
12
  
13
  // Protect against forgetting the new keyword when calling the constructor
14
  if(!(this instanceof NamePart)){
15
    return new NamePart(json);
16
  }
17
  
18
  // If the given object is already an instance then just return it. DON'T copy it.
19
  if(NamePart.isInstance(json)){
20
    return json;
21
  }
22
  
23
  ExtensibleData.call(this, json);
24
  
25
  if(json){
26
    this.setValue(json.value);
27
    this.setType(json.type);
28
    this.setQualifiers(json.qualifiers);
29
  }
30
};
31
32
NamePart.prototype = Object.create(ExtensibleData.prototype);
33
34
NamePart._gedxClass = NamePart.prototype._gedxClass = 'GedcomX.NamePart';
35
36
/**
37
 * Check whether the given object is an instance of this class.
38
 * 
39
 * @param {Object} obj
40
 * @returns {Boolean}
41
 */
42
NamePart.isInstance = function(obj){
43
  return utils.isInstance(obj, this._gedxClass);
44
};
45
46
/**
47
 * Get the type
48
 * 
49
 * @returns {String} type
50
 */
51
NamePart.prototype.getType = function(){
52
  return this.type;
53
};
54
55
/**
56
 * Set the type
57
 * 
58
 * @param {String} type
59
 * @returns {NamePart} This instance
60
 */
61
NamePart.prototype.setType = function(type){
62
  this.type = type;
63
  return this;
64
};
65
66
/**
67
 * Get the value
68
 * 
69
 * @returns {String}
70
 */
71
NamePart.prototype.getValue = function(){
72
  return this.value;
73
};
74
75
/**
76
 * Set the value
77
 * 
78
 * @param {String} value
79
 * @returns {NamePart} This instance
80
 */
81
NamePart.prototype.setValue = function(value){
82
  this.value = value;
83
  return this;
84
};
85
86
/**
87
 * Get qualifiers
88
 * 
89
 * @return {Qualifer[]}
90
 */
91
NamePart.prototype.getQualifiers = function(){
92
  return this.qualifiers || [];
93
};
94
95
/**
96
 * Set the qualifiers
97
 * 
98
 * @param {Qualifer[]|Object[]} qualifiers
99
 * @returns {NamePart} This instance
100
 */
101
NamePart.prototype.setQualifiers = function(qualifiers){
102
  return this._setArray(qualifiers, 'qualifiers', 'addQualifier');
103
};
104
105
/**
106
 * Add a qualifier
107
 * 
108
 * @param {Qualifier|Object} qualifier
109
 * @returns {NamePart} This instance
110
 */
111
NamePart.prototype.addQualifier = function(qualifier){
112
  return this._arrayPush(qualifier, 'qualifiers', Qualifier);
113
};
114
115
/**
116
 * Export the object as JSON
117
 * 
118
 * @return {Object} JSON object
119
 */
120
NamePart.prototype.toJSON = function(){
121
  return this._toJSON(ExtensibleData, [
122
    'type',
123
    'value',
124
    'qualifiers'
125
  ]);
126
};
127
128
module.exports = NamePart;