Code Duplication    Length = 167-189 lines in 2 locations

src/core/Fact.js 1 location

@@ 1-189 (lines=189) @@
1
var GedcomX = require('../'),
2
    utils = require('../utils');
3
4
/**
5
 * A fact for a person or relationship.
6
 * 
7
 * @see {@link https://github.com/FamilySearch/gedcomx/blob/master/specifications/json-format-specification.md#fact-conclusion|GEDCOM X JSON Spec}
8
 * 
9
 * @class
10
 * @extends Conclusion
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
  this.init(json);
26
};
27
28
Fact.prototype = Object.create(GedcomX.Conclusion.prototype);
29
30
Fact._gedxClass = Fact.prototype._gedxClass = 'GedcomX.Fact';
31
32
Fact.jsonProps = [
33
  'type',
34
  'date',
35
  'place',
36
  'value',
37
  'qualifiers'
38
];
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
 * Initialize from JSON
52
 * 
53
 * @param {Object}
54
 * @return {Fact} this
55
 */
56
Fact.prototype.init = function(json){
57
  
58
  GedcomX.Conclusion.prototype.init.call(this, json);
59
  
60
  if(json){
61
    this.setType(json.type);
62
    this.setDate(json.date);
63
    this.setPlace(json.place);
64
    this.setValue(json.value);
65
    this.setQualifiers(json.qualifiers);
66
  }
67
  return this;
68
};
69
70
/**
71
 * Get the fact type
72
 * 
73
 * @returns {String} type
74
 */
75
Fact.prototype.getType = function(){
76
  return this.type;
77
};
78
79
/**
80
 * Set the fact type
81
 * 
82
 * @param {String} type
83
 * @returns {Fact} This instance
84
 */
85
Fact.prototype.setType = function(type){
86
  this.type = type;
87
  return this;
88
};
89
90
/**
91
 * Get the date
92
 * 
93
 * @returns {Date} date
94
 */
95
Fact.prototype.getDate = function(){
96
  return this.date;
97
};
98
99
/**
100
 * Set the date
101
 * 
102
 * @param {Date|Object} date
103
 * @returns {Fact} This instance
104
 */
105
Fact.prototype.setDate = function(date){
106
  if(date){
107
    this.date = GedcomX.Date(date);
108
  }
109
  return this;
110
};
111
112
/**
113
 * Get the place reference
114
 * 
115
 * @returns {PlaceReference}
116
 */
117
Fact.prototype.getPlace = function(){
118
  return this.place;
119
};
120
121
/**
122
 * Set the place reference
123
 *
124
 * @param {PlaceReference|Object} place
125
 * @returns {Fact} This instance
126
 */
127
Fact.prototype.setPlace = function(place){
128
  if(place){
129
    this.place = GedcomX.PlaceReference(place);
130
  }
131
  return this;
132
};
133
134
/**
135
 * Get the value
136
 * 
137
 * @returns {String}
138
 */
139
Fact.prototype.getValue = function(){
140
  return this.value;
141
};
142
143
/**
144
 * Set the value
145
 * 
146
 * @param {String} value
147
 * @returns {Fact} This instance
148
 */
149
Fact.prototype.setValue = function(value){
150
  this.value = value;
151
  return this;
152
};
153
154
/**
155
 * Get qualifiers
156
 * 
157
 * @return {Qualifer[]}
158
 */
159
Fact.prototype.getQualifiers = function(){
160
  return this.qualifiers || [];
161
};
162
163
/**
164
 * Set the qualifiers
165
 * 
166
 * @param {Qualifer[]|Object[]} qualifiers
167
 * @returns {Fact} This instance
168
 */
169
Fact.prototype.setQualifiers = function(qualifiers){
170
  return this._setArray(qualifiers, 'qualifiers', 'addQualifier');
171
};
172
173
/**
174
 * Add a qualifier
175
 * 
176
 * @param {Qualifier|Object} qualifier
177
 * @returns {Fact} This instance
178
 */
179
Fact.prototype.addQualifier = function(qualifier){
180
  return this._arrayPush(qualifier, 'qualifiers', GedcomX.Qualifier);
181
};
182
183
/**
184
 * Export the object as JSON
185
 * 
186
 * @return {Object} JSON object
187
 */
188
Fact.prototype.toJSON = function(){
189
  return this._toJSON(GedcomX.Conclusion, Fact.jsonProps);
190
};
191
192
module.exports = Fact;

src/core/Event.js 1 location

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