Completed
Push — master ( e193d1...415e1b )
by Justin
01:32
created

src/atom/AtomGenerator.js   A

Complexity

Total Complexity 14
Complexity/F 1.27

Size

Lines of Code 136
Function Count 11

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 0
c 1
b 0
f 0
nc 1
dl 0
loc 136
rs 10
wmc 14
mnd 1
bc 14
fnc 11
bpm 1.2727
cpm 1.2727
noi 3
1
module.exports = function(GedcomX){
2
3
  var utils = require('../utils'),
4
      AtomCommon = require('./AtomCommon');
5
  
6
  /**
7
   * The agent used to generate a feed
8
   * 
9
   * @constructor
10
   * @param {Object} [json]
0 ignored issues
show
Documentation introduced by
The parameter [json] does not exist. Did you maybe forget to remove this comment?
Loading history...
11
   */
12
  var AtomGenerator = function(json){
13
    
14
    // Protect against forgetting the new keyword when calling the constructor
15
    if(!(this instanceof AtomGenerator)){
16
      return new AtomGenerator(json);
17
    }
18
    
19
    // If the given object is already an instance then just return it. DON'T copy it.
20
    if(AtomGenerator.isInstance(json)){
21
      return json;
22
    }
23
    
24
    this.init(json);
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
25
  };
26
  
27
  AtomGenerator.prototype = Object.create(AtomCommon.prototype);
28
  
29
  AtomGenerator._gedxClass = AtomGenerator.prototype._gedxClass = 'GedcomX.AtomGenerator';
30
  
31
  AtomGenerator.jsonProps = [
32
    'uri',
33
    'version',
34
    'value'
35
  ];
36
  
37
  /**
38
   * Check whether the given object is an instance of this class.
39
   * 
40
   * @param {Object} obj
41
   * @returns {Boolean}
42
   */
43
  AtomGenerator.isInstance = function(obj){
44
    return utils.isInstance(obj, this._gedxClass);
45
  };
46
47
  /**
48
   * Initialize from JSON
49
   * 
50
   * @param {Object}
0 ignored issues
show
Documentation introduced by
The parameter * does not exist. Did you maybe forget to remove this comment?
Loading history...
51
   * @return {AtomGenerator} this
52
   */
53
  AtomGenerator.prototype.init = function(json){
54
    
55
    AtomCommon.prototype.init.call(this, json);
56
    
57
    if(json){
58
      this.setUri(json.uri);
59
      this.setVersion(json.version);
60
      this.setValue(json.value);
61
    }
62
    return this;
63
  };
64
  
65
  /**
66
   * Set the uri
67
   * 
68
   * @param {String} uri
69
   * @return {AtomGenerator} this
70
   */
71
  AtomGenerator.prototype.setUri = function(uri){
72
    this.uri = uri;
73
    return this;
74
  };
75
  
76
  /**
77
   * Get the uri
78
   * 
79
   * @return {String} this
80
   */
81
  AtomGenerator.prototype.getUri = function(){
82
    return this.uri;
83
  };
84
  
85
  /**
86
   * Set the version
87
   * 
88
   * @param {String} version
89
   * @return {AtomGenerator} this
90
   */
91
  AtomGenerator.prototype.setVersion = function(version){
92
    this.version = version;
93
    return this;
94
  };
95
  
96
  /**
97
   * Get the version
98
   * 
99
   * @return {String} this
100
   */
101
  AtomGenerator.prototype.getVersion = function(){
102
    return this.version;
103
  };
104
  
105
  /**
106
   * Set the value
107
   * 
108
   * @param {String} value
109
   * @return {AtomGenerator} this
110
   */
111
  AtomGenerator.prototype.setValue = function(value){
112
    this.value = value;
113
    return this;
114
  };
115
  
116
  /**
117
   * Get the value
118
   * 
119
   * @return {String} this
120
   */
121
  AtomGenerator.prototype.getValue = function(){
122
    return this.value;
123
  };
124
  
125
  /**
126
   * Export the object as JSON
127
   * 
128
   * @return {Object} JSON object
129
   */
130
  AtomGenerator.prototype.toJSON = function(){
131
    return this._toJSON(AtomCommon, AtomGenerator.jsonProps);
132
  };
133
  
134
  GedcomX.AtomGenerator = AtomGenerator;
135
136
};