Passed
Push — master ( c4d61c...59bf76 )
by Kolja
01:06
created

jgfContainer.js   A

Complexity

Total Complexity 9
Complexity/F 1.8

Size

Lines of Code 63
Function Count 5

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 0
wmc 9
eloc 23
c 0
b 0
f 0
nc 1
mnd 1
bc 8
fnc 5
dl 0
loc 63
rs 10
bpm 1.6
cpm 1.8
noi 0

5 Functions

Rating   Name   Duplication   Size   Complexity  
A ➔ isMultiGraph 0 3 1
A ➔ constructor 0 8 2
A ➔ graph 0 7 2
A ➔ addEmptyGraph 0 6 1
A ➔ graphs 0 7 2
1
const { JGFGraph } = require('./jgfGraph');
2
3
/**
4
 * JGF Container (main class) of zero or more JGF graphs
5
 */
6
class JGFContainer {
7
8
    /**
9
     * Constructor
10
     * @param {*} singleGraph true for single-graph mode, false for multi-graph mode
11
     */
12
    constructor(singleGraph = true) {
13
        this._graphs = [];
14
        this.isSingleGraph = singleGraph;
15
16
        if (singleGraph) {
17
            this.addEmptyGraph();
18
        }
19
    }
20
21
    /**
22
     * Returns all graphs, in Multi-Graph mode
23
     */
24
    get graphs() {
25
        if (this.isSingleGraph) {
26
            throw new Error('Cannot call graphs() in Single-Graph mode')
27
        }
28
29
        return this._graphs;
30
    }
31
32
    /**
33
     * Returns the graph, in Single-Graph mode
34
     */
35
    get graph() {
36
        if (!this.isSingleGraph) {
37
            throw new Error('Cannot call graph() in Multi-Graph mode')
38
        }
39
40
        return this._graphs[0];
41
    }
42
43
    /**
44
     * Returns true if the container is in Multi-Graph mode
45
     */
46
    get isMultiGraph() {
47
        return !this.isSingleGraph;
48
    }
49
50
    /**
51
     * Adds an empty graph
52
     */
53
    addEmptyGraph() {
54
        let graph = new JGFGraph();
55
        this._graphs.push(graph);
56
57
        return graph;
58
    }
59
}
60
61
module.exports = {
62
    JGFContainer,
63
};