Passed
Push — master ( 1e6bfa...39280d )
by Kolja
01:03
created

jgfNode.js   A

Complexity

Total Complexity 11
Complexity/F 1.38

Size

Lines of Code 56
Function Count 8

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 0
eloc 25
c 1
b 0
f 0
nc 1
dl 0
loc 56
rs 10
wmc 11
mnd 1
bc 10
fnc 8
bpm 1.25
cpm 1.375
noi 0

5 Functions

Rating   Name   Duplication   Size   Complexity  
A ➔ constructor 0 5 1
A ➔ metadata 0 6 2
A ➔ label 0 3 1
A ➔ id 0 3 1
A ➔ _guardAgainstInvalidMetaData 0 5 2
1
const check = require('check-types');
2
3
/**
4
 * A node object represents a node in a graph.
5
 */
6
class JGFNode {
7
8
    /**
9
     * Constructor
10
     * @param {string} id Primary key for the node, that is unique for the object type.
11
     * @param {string} label A text display for the node.
12
     * @param {object,null} metadata Metadata about the node.
13
     */
14
    constructor(id, label, metadata = null) {
15
        this._id = id;
16
        this._label = label;
17
        this.metadata = metadata;
18
    }
19
20
    static _guardAgainstInvalidMetaData(metadata) {
21
        if (!check.nonEmptyObject(metadata)) {
22
            throw Error('Metadata on an node has to be an object.');
23
        }
24
    }
25
26
    set id(id) {
27
        this._id = id;
28
    }
29
30
    get id() {
31
        return this._id;
32
    }
33
34
    set label(label) {
35
        this._label = label;
36
    }
37
38
    get label() {
39
        return this._label;
40
    }
41
42
    set metadata(metadata) {
43
        if (check.assigned(metadata)) {
44
            JGFNode._guardAgainstInvalidMetaData(metadata);
45
        }
46
        this._metadata = metadata;
47
    }
48
49
    get metadata() {
50
        return this._metadata;
51
    }
52
}
53
54
module.exports = {
55
    JGFNode,
56
};