Code Duplication    Length = 155-208 lines in 3 locations

src/Fact.js 1 location

@@ 1-208 (lines=208) @@
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
  if(Array.isArray(qualifiers)){
151
    this.qualifiers = [];
152
    var fact = this;
153
    qualifiers.forEach(function(q){
154
      fact.addQualifier(q);
155
    });
156
  }
157
};
158
159
/**
160
 * Add a qualifier
161
 * 
162
 * @param {Qualifier|Object} qualifier
163
 * @returns {Fact} This instance
164
 */
165
Fact.prototype.addQualifier = function(qualifier){
166
  if(qualifier){
167
    if(!Array.isArray(this.qualifiers)){
168
      this.qualifiers = [];
169
    }
170
    this.qualifiers.push(Qualifier(qualifier));
171
  }
172
  return this;
173
};
174
175
/**
176
 * Export the object as JSON
177
 * 
178
 * @return {Object} JSON object
179
 */
180
Fact.prototype.toJSON = function(){
181
  var json = Conclusion.prototype.toJSON.call(this);
182
  
183
  if(this.type){
184
    json.type = this.type;
185
  }
186
  
187
  if(this.date){
188
    json.date = this.date.toJSON();
189
  }
190
  
191
  if(this.place){
192
    json.place = this.place.toJSON();
193
  }
194
  
195
  if(this.value){
196
    json.value = this.value;
197
  }
198
  
199
  if(this.qualifiers){
200
    json.qualifiers = this.qualifiers.map(function(q){
201
      return q.toJSON();
202
    });
203
  }
204
  
205
  return json;
206
};
207
208
module.exports = Fact;

src/Event.js 1 location

@@ 1-184 (lines=184) @@
1
var Subject = require('./Subject'),
2
    GDate = require('./Date'),
3
    PlaceReference = require('./PlaceReference'),
4
    EventRole = require('./EventRole'),
5
    utils = require('./utils');
6
7
/**
8
 * An event.
9
 * 
10
 * @constructor
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
  Subject.call(this, json);
26
  
27
  if(json){
28
    this.setType(json.type);
29
    this.setDate(json.date);
30
    this.setPlace(json.place);
31
    this.setRoles(json.roles);
32
  }
33
};
34
35
Event.prototype = Object.create(Subject.prototype);
36
37
Event._gedxClass = Event.prototype._gedxClass = 'GedcomX.Event';
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
 * Get the type
51
 * 
52
 * @returns {String}
53
 */
54
Event.prototype.getType = function(){
55
  return this.type;
56
};
57
58
/**
59
 * Set the type
60
 * 
61
 * @param {String} type
62
 * @returns {Event}
63
 */
64
Event.prototype.setType = function(type){
65
  this.type = type;
66
  return this;
67
};
68
69
/**
70
 * Get the date
71
 * 
72
 * @returns {Date}
73
 */
74
Event.prototype.getDate = function(){
75
  return this.date;
76
};
77
78
/**
79
 * Set the date
80
 * 
81
 * @param {Date} date
82
 * @returns {Event}
83
 */
84
Event.prototype.setDate = function(date){
85
  if(date){
86
    this.date = GDate(date);
87
  }
88
  return this;
89
};
90
91
/**
92
 * Get the place
93
 * 
94
 * @returns {PlaceReference}
95
 */
96
Event.prototype.getPlace = function(){
97
  return this.place;
98
};
99
100
/**
101
 * Set the place
102
 * 
103
 * @param {PlaceReference} place
104
 * @returns {Event}
105
 */
106
Event.prototype.setPlace = function(place){
107
  if(place){
108
    this.place = PlaceReference(place);
109
  }
110
  return this;
111
};
112
113
/**
114
 * Get the roles
115
 * 
116
 * @returns {EventRole[]}
117
 */
118
Event.prototype.getRoles = function(){
119
  return this.roles || [];
120
};
121
122
/**
123
 * Set the roles
124
 * 
125
 * @param {EventRole[]|Object[]} roles
126
 * @returns {Event}
127
 */
128
Event.prototype.setRoles = function(roles){
129
  if(Array.isArray(roles)){
130
    var event = this;
131
    event.roles = [];
132
    roles.forEach(function(r){
133
      event.addRole(r);
134
    });
135
  }
136
  return this;
137
};
138
139
/**
140
 * Add a role
141
 * 
142
 * @param {EventRole|Object} role
143
 * @returns {Event}
144
 */
145
Event.prototype.addRole = function(role){
146
  if(role){
147
    if(!Array.isArray(this.roles)){
148
      this.roles = [];
149
    }
150
    this.roles.push(EventRole(role));
151
  }
152
  return this;
153
};
154
155
/**
156
 * Export the object as JSON
157
 * 
158
 * @return {Object} JSON object
159
 */
160
Event.prototype.toJSON = function(){
161
  var json = Subject.prototype.toJSON.call(this);
162
  
163
  if(this.type){
164
    json.type = this.type;
165
  }
166
  
167
  if(this.date){
168
    json.date = this.date.toJSON();
169
  }
170
  
171
  if(this.place){
172
    json.place = this.place.toJSON();
173
  }
174
  
175
  if(this.roles){
176
    json.roles = this.roles.map(function(r){
177
      return r.toJSON();
178
    });
179
  }
180
  
181
  return json;
182
};
183
184
module.exports = Event;

src/Name.js 1 location

@@ 1-155 (lines=155) @@
1
var Conclusion = require('./Conclusion'),
2
    NameForm = require('./NameForm'),
3
    GDate = require('./Date'),
4
    utils = require('./utils');
5
6
/**
7
 * A name.
8
 * 
9
 * @constructor
10
 * @param {Object} [json]
11
 */
12
var Name = function(json){
13
  
14
  // Protect against forgetting the new keyword when calling the constructor
15
  if(!(this instanceof Name)){
16
    return new Name(json);
17
  }
18
  
19
  // If the given object is already an instance then just return it. DON'T copy it.
20
  if(Name.isInstance(json)){
21
    return json;
22
  }
23
  
24
  Conclusion.call(this, json);
25
  
26
  if(json){
27
    this.setType(json.type);
28
    this.setDate(json.date);
29
    this.setNameForms(json.nameForms);
30
  }
31
};
32
33
Name.prototype = Object.create(Conclusion.prototype);
34
35
Name._gedxClass = Name.prototype._gedxClass = 'GedcomX.Name';
36
37
/**
38
 * Check whether the given object is an instance of this class.
39
 * 
40
 * @param {Object} obj
41
 * @returns {Boolean}
42
 */
43
Name.isInstance = function(obj){
44
  return utils.isInstance(obj, this._gedxClass);
45
};
46
47
/**
48
 * Get the name type
49
 * 
50
 * @returns {String} type
51
 */
52
Name.prototype.getType = function(){
53
  return this.type;
54
};
55
56
/**
57
 * Set the name type
58
 * 
59
 * @param {String} type
60
 * @returns {Name} This instance
61
 */
62
Name.prototype.setType = function(type){
63
  this.type = type;
64
  return this;
65
};
66
67
/**
68
 * Get the date
69
 * 
70
 * @returns {Date} date
71
 */
72
Name.prototype.getDate = function(){
73
  return this.date;
74
};
75
76
/**
77
 * Set the date
78
 * 
79
 * @param {Date|Object} date
80
 * @returns {Fact} This instance
81
 */
82
Name.prototype.setDate = function(date){
83
  if(date){
84
    this.date = GDate(date);
85
  }
86
  return this;
87
};
88
89
/**
90
 * Get the name forms
91
 * 
92
 * @return {NameForm[]}
93
 */
94
Name.prototype.getNameForms = function(){
95
  return this.nameForms || [];
96
};
97
98
/**
99
 * Set the name forms
100
 * 
101
 * @param {NameForm[]|Object[]} nameForms
102
 * @returns {Name} This instance
103
 */
104
Name.prototype.setNameForms = function(nameForms){
105
  if(Array.isArray(nameForms)){
106
    this.nameForms = [];
107
    var name = this;
108
    nameForms.forEach(function(n){
109
      name.addNameForm(n);
110
    });
111
  }
112
};
113
114
/**
115
 * Add a name form
116
 * 
117
 * @param {NameForm|Object} nameForm
118
 * @returns {Name} This instance
119
 */
120
Name.prototype.addNameForm = function(nameForm){
121
  if(nameForm){
122
    if(!Array.isArray(this.nameForms)){
123
      this.nameForms = [];
124
    }
125
    this.nameForms.push(NameForm(nameForm));
126
  }
127
  return this;
128
};
129
130
/**
131
 * Export the object as JSON
132
 * 
133
 * @return {Object} JSON object
134
 */
135
Name.prototype.toJSON = function(){
136
  var json = Conclusion.prototype.toJSON.call(this);
137
  
138
  if(this.type){
139
    json.type = this.type;
140
  }
141
  
142
  if(this.date){
143
    json.date = this.date.toJSON();
144
  }
145
  
146
  if(this.nameForms){
147
    json.nameForms = this.nameForms.map(function(n){
148
      return n.toJSON();
149
    });
150
  }
151
  
152
  return json;
153
};
154
155
module.exports = Name;