summaryrefslogtreecommitdiffstats
path: root/lib/models/glossaryEntry.js
blob: 9c390c5cbbb179116ac333a9c8dee57fbfde3ebd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
var Immutable = require('immutable');

/*
    A definition represents an entry in the glossary
*/

var GlossaryEntry = Immutable.Record({
    name:               String(),
    description:        String()
});

GlossaryEntry.prototype.getName = function() {
    return this.get('name');
};

GlossaryEntry.prototype.getDescription = function() {
    return this.get('description');
};


/**
    Get identifier for this entry

    @retrun {Boolean}
*/
GlossaryEntry.prototype.getID = function() {
    return GlossaryEntry.nameToID(this.getName());
};


/**
    Normalize a glossary entry name into a unique id

    @param {String}
    @return {String}
*/
GlossaryEntry.nameToID = function nameToID(name) {
    return name.toLowerCase()
        .replace(/[\/\\\?\%\*\:\;\|\"\'\\<\\>\#\$\(\)\!\.\@]/g, '')
        .replace(/ /g, '_')
        .trim();
};


module.exports = GlossaryEntry;