Passed
Branch master (32b4c5)
by Askupa
01:33
created

src/js/mivhak.resources.js   A

Complexity

Total Complexity 5
Complexity/F 1

Size

Lines of Code 47
Function Count 5

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 0
c 2
b 0
f 0
nc 1
dl 0
loc 47
rs 10
wmc 5
mnd 0
bc 5
fnc 5
bpm 1
cpm 1
noi 1
1
/**
2
 * Any <pre> element inside the mivhak wrapper is considered to be a Mivhak 
3
 * resource. When a new Mivhak instance is created, the list of resources is 
4
 * parsed nad stored in this object.
5
 * 
6
 * @returns {Resources}
7
 */
8
var Resources = function() {
9
    this.data = [];
10
};
11
12
/**
13
 * Return the number of resources
14
 * @returns {Number}
15
 */
16
Resources.prototype.count = function() {
17
    return this.data.length;
18
};
19
20
/**
21
 * Add a resource to the list. Given a <pre> element, this function will extract
22
 * all the attributes beginning with 'miv-' and the element's content and insert
23
 * it to the list of resources.
24
 * 
25
 * @param {DOMElement} pre
26
 */
27
Resources.prototype.add = function(pre) {
28
    this.data.push($.extend({},
29
        Mivhak.resourceDefaults,{
30
            pre:pre, 
31
            content: pre.textContent
32
        },
33
        readAttributes(pre)
34
    ));
35
};
36
37
/**
38
 * Get a resource by a given index
39
 * @param {Number} i
40
 * @returns {Object}
41
 */
42
Resources.prototype.get = function(i) {
43
    return this.data[i];
44
};
45
46
/**
47
 * Update the content of the resource corresponding to the given index.
48
 * 
49
 * @param {number} i
50
 * @param {string} content
51
 */
52
Resources.prototype.update = function(i, content) {
53
    this.data[i].content = content;
54
};
55
56