Code Duplication    Length = 190-220 lines in 2 locations

src/core/Conclusion.js 1 location

@@ 1-220 (lines=220) @@
1
var GedcomX = require('../'),
2
    utils = require('../utils');
3
4
/**
5
 * An abstract concept for a basic genealogical data item.
6
 * 
7
 * @see {@link https://github.com/FamilySearch/gedcomx/blob/master/specifications/json-format-specification.md#conclusion|GEDCOM X JSON Spec}
8
 * 
9
 * @class
10
 * @extends ExtensibleData
11
 * @param {Object} [json]
12
 */
13
var Conclusion = function(json){
14
  
15
  // Protect against forgetting the new keyword when calling the constructor
16
  if(!(this instanceof Conclusion)){
17
    return new Conclusion(json);
18
  }
19
  
20
  // If the given object is already an instance then just return it. DON'T copy it.
21
  if(Conclusion.isInstance(json)){
22
    return json;
23
  }
24
  
25
  this.init(json);
26
};
27
28
Conclusion.prototype = Object.create(GedcomX.ExtensibleData.prototype);
29
30
Conclusion._gedxClass = Conclusion.prototype._gedxClass = 'GedcomX.Conclusion';
31
32
Conclusion.jsonProps = [
33
  'lang',
34
  'confidence',
35
  'analysis',
36
  'attribution',
37
  'sources',
38
  'notes'
39
];
40
41
/**
42
 * Check whether the given object is an instance of this class.
43
 * 
44
 * @param {Object} obj
45
 * @returns {Boolean}
46
 */
47
Conclusion.isInstance = function(obj){
48
  return utils.isInstance(obj, this._gedxClass);
49
};
50
51
/**
52
 * Initialize from JSON
53
 * 
54
 * @param {Object}
55
 * @return {Conclusion} this
56
 */
57
Conclusion.prototype.init = function(json){
58
  
59
  GedcomX.ExtensibleData.prototype.init.call(this, json);
60
  
61
  if(json){
62
    this.setAttribution(json.attribution);
63
    this.setAnalysis(json.analysis);
64
    this.setConfidence(json.confidence);
65
    this.setLang(json.lang);
66
    this.setNotes(json.notes);
67
    this.setSources(json.sources);
68
  }
69
  return this;
70
};
71
72
/**
73
 * Get the attribution.
74
 * 
75
 * @returns {Attribution}
76
 */
77
Conclusion.prototype.getAttribution = function(){
78
  return this.attribution;
79
};
80
81
/**
82
 * Set the attribution
83
 * 
84
 * @param {Object|Attribution} attribution
85
 * @returns {Conclusion} This instance
86
 */
87
Conclusion.prototype.setAttribution = function(attribution){
88
  if(attribution){
89
    this.attribution = new GedcomX.Attribution(attribution);
90
  }
91
  return this;
92
};
93
94
/**
95
 * Get analysis.
96
 * 
97
 * @returns {ResourceReference} analysis
98
 */
99
Conclusion.prototype.getAnalysis = function(){
100
  return this.analysis;
101
};
102
103
/**
104
 * Set the analysis
105
 * 
106
 * @param {Object|ResourceReference} analysis
107
 * @returns {Conclusion} This instance
108
 */
109
Conclusion.prototype.setAnalysis = function(analysis){
110
  if(analysis){
111
    this.analysis = new GedcomX.ResourceReference(analysis);
112
  }
113
  return this;
114
};
115
116
/**
117
 * Get the confidence.
118
 * 
119
 * @returns {String} confidence
120
 */
121
Conclusion.prototype.getConfidence = function(){
122
  return this.confidence;
123
};
124
125
/**
126
 * Set the confidence.
127
 * 
128
 * @param {String} confidence
129
 * @returns {Conclusion} This instance
130
 */
131
Conclusion.prototype.setConfidence = function(confidence){
132
  this.confidence = confidence;
133
  return this;
134
};
135
136
/**
137
 * Get the language identifier.
138
 * 
139
 * @returns {String} lang
140
 */
141
Conclusion.prototype.getLang = function(){
142
  return this.lang;
143
};
144
145
/**
146
 * Set the language identifier.
147
 * 
148
 * @param {String} lang
149
 * @returns {Conclusion} This instance.
150
 */
151
Conclusion.prototype.setLang = function(lang){
152
  this.lang = lang;
153
  return this;
154
};
155
156
/**
157
 * Get the notes
158
 * 
159
 * @returns {Note[]} notes
160
 */
161
Conclusion.prototype.getNotes = function(){
162
  return this.notes || [];
163
};
164
165
/**
166
 * Set the notes
167
 * 
168
 * @param {Object[]|Note[]} notes
169
 * @returns {Conclusion} This instance
170
 */
171
Conclusion.prototype.setNotes = function(notes){
172
  return this._setArray(notes, 'notes', 'addNote');
173
};
174
175
/**
176
 * Add a note
177
 * 
178
 * @param {Object|Note} note
179
 * @returns {Conclusion} This instance
180
 */
181
Conclusion.prototype.addNote = function(note){
182
  return this._arrayPush(note, 'notes', GedcomX.Note);
183
};
184
185
/**
186
 * Get the sources
187
 * 
188
 * @returns {SourceReference[]}
189
 */
190
Conclusion.prototype.getSources = function(){
191
  return this.sources || [];
192
};
193
194
/**
195
 * Set the sources
196
 * 
197
 * @param {Object[]|SourceReference[]} sources
198
 * @returns {Conclusion} This instance
199
 */
200
Conclusion.prototype.setSources = function(sources){
201
  return this._setArray(sources, 'sources', 'addSource');
202
};
203
204
/**
205
 * Add a source
206
 * 
207
 * @param {SourceReference} source
208
 * @returns {Conclusion} This instance
209
 */
210
Conclusion.prototype.addSource = function(source){
211
  return this._arrayPush(source, 'sources', GedcomX.SourceReference);
212
};
213
214
/**
215
 * Export the object as JSON
216
 * 
217
 * @return {Object} JSON object
218
 */
219
Conclusion.prototype.toJSON = function(){
220
  return this._toJSON(GedcomX.ExtensibleData, Conclusion.jsonProps);
221
};
222
223
module.exports = Conclusion;

src/records/Collection.js 1 location

@@ 1-190 (lines=190) @@
1
module.exports = function(GedcomX){
2
  
3
  var utils = require('../utils');
4
  
5
  /**
6
   * A collection of genealogical data.
7
   * 
8
   * @see {@link https://github.com/FamilySearch/gedcomx-record/blob/master/specifications/record-specification.md#collection|GEDCOM X Records Spec}
9
   * 
10
   * @class Collection
11
   * @extends ExtensibleData
12
   * @param {Object} [json]
13
   */
14
  var Collection = function(json){
15
    
16
    // Protect against forgetting the new keyword when calling the constructor
17
    if(!(this instanceof Collection)){
18
      return new Collection(json);
19
    }
20
    
21
    // If the given object is already an instance then just return it. DON'T copy it.
22
    if(Collection.isInstance(json)){
23
      return json;
24
    }
25
    
26
    this.init(json);
27
  };
28
  
29
  Collection.prototype = Object.create(GedcomX.ExtensibleData.prototype);
30
  
31
  Collection._gedxClass = Collection.prototype._gedxClass = 'GedcomX.Collection';
32
  
33
  Collection.jsonProps = [
34
    'lang',
35
    'content',
36
    'title',
37
    'size',
38
    'attribution'
39
  ];
40
  
41
  /**
42
   * Check whether the given object is an instance of this class.
43
   * 
44
   * @param {Object} obj
45
   * @returns {Boolean}
46
   */
47
  Collection.isInstance = function(obj){
48
    return utils.isInstance(obj, this._gedxClass);
49
  };
50
51
  /**
52
   * Initialize from JSON
53
   * 
54
   * @param {Object}
55
   * @return {Collection} this
56
   */
57
  Collection.prototype.init = function(json){
58
    
59
    GedcomX.ExtensibleData.prototype.init.call(this, json);
60
    
61
    if(json){
62
      this.setLang(json.lang);
63
      this.setContent(json.content);
64
      this.setTitle(json.title);
65
      this.setSize(json.size);
66
      this.setAttribution(json.attribution);
67
    }
68
    return this;
69
  };
70
  
71
  /**
72
   * Set the lang
73
   * 
74
   * @param {String} lang
75
   * @return {Collection} this
76
   */
77
  Collection.prototype.setLang = function(lang){
78
    this.lang = lang;
79
    return this;
80
  };
81
  
82
  /**
83
   * Get lang
84
   * 
85
   * @return {String} lang
86
   */
87
  Collection.prototype.getLang = function(){
88
    return this.lang;
89
  };
90
  
91
  /**
92
   * Set the content
93
   * 
94
   * @param {CollectionContent[]} content
95
   * @return {Collection} this
96
   */
97
  Collection.prototype.setContent = function(content){
98
    return this._setArray(content, 'content', 'addContent');
99
  };
100
  
101
  /**
102
   * Add a collection content
103
   * 
104
   * @param {CollectionContent} content
105
   * @return {Collection} this
106
   */
107
  Collection.prototype.addContent = function(content){
108
    return this._arrayPush(content, 'content', GedcomX.CollectionContent);
109
  };
110
  
111
  /**
112
   * Get content
113
   * 
114
   * @return {CollectionContent[]}
115
   */
116
  Collection.prototype.getContent = function(){
117
    return this.content || [];
118
  };
119
  
120
  /**
121
   * Set the title
122
   * 
123
   * @param {String} title
124
   * @return {Collection} this
125
   */
126
  Collection.prototype.setTitle = function(title){
127
    this.title = title;
128
    return this;
129
  };
130
  
131
  /**
132
   * Get the title
133
   * 
134
   * @return {String} title
135
   */
136
  Collection.prototype.getTitle = function(){
137
    return this.title;
138
  };
139
  
140
  /**
141
   * Set the size
142
   * 
143
   * @param {Number} size
144
   * @return {Collection} this
145
   */
146
  Collection.prototype.setSize = function(size){
147
    this.size = size;
148
    return this;
149
  };
150
  
151
  /**
152
   * Get the size
153
   * 
154
   * @return {Number}
155
   */
156
  Collection.prototype.getSize = function(){
157
    return this.size;
158
  };
159
  
160
  /**
161
   * Set the attribution
162
   * 
163
   * @param {Attribution}
164
   * @return {Collection} this
165
   */
166
  Collection.prototype.setAttribution = function(attribution){
167
    if(attribution){
168
      this.attribution = GedcomX.Attribution(attribution);
169
    }
170
    return this;
171
  };
172
  
173
  /**
174
   * Get the attribution
175
   * 
176
   * @return {Attribution}
177
   */
178
  Collection.prototype.getAttribution = function(){
179
    return this.attribution;
180
  };
181
   
182
  /**
183
   * Export the object as JSON
184
   * 
185
   * @return {Object} JSON object
186
   */
187
  Collection.prototype.toJSON = function(){
188
    return this._toJSON(GedcomX.ExtensibleData, Collection.jsonProps);
189
  };
190
  
191
  GedcomX.Collection = Collection;
192
  
193
};