diff options
Diffstat (limited to 'packages/gitbook/src/models/glossaryEntry.js')
-rw-r--r-- | packages/gitbook/src/models/glossaryEntry.js | 78 |
1 files changed, 42 insertions, 36 deletions
diff --git a/packages/gitbook/src/models/glossaryEntry.js b/packages/gitbook/src/models/glossaryEntry.js index b36b276..35ea1ca 100644 --- a/packages/gitbook/src/models/glossaryEntry.js +++ b/packages/gitbook/src/models/glossaryEntry.js @@ -1,43 +1,49 @@ -const Immutable = require('immutable'); +const { Record } = require('immutable'); const slug = require('github-slugid'); -/* - A definition represents an entry in the glossary -*/ - -const GlossaryEntry = Immutable.Record({ - name: String(), - description: String() -}); - -GlossaryEntry.prototype.getName = function() { - return this.get('name'); -}; - -GlossaryEntry.prototype.getDescription = function() { - return this.get('description'); +const DEFAULTS = { + name: String(), + description: String() }; - /** - 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 slug(name); -}; - + * A definition represents an entry in the glossary. + * @param {Class} + */ + +class GlossaryEntry extends Record(DEFAULTS) { + + /** + * Get identifier for this entry + * + * @return {String} + */ + get id() { + return GlossaryEntry.nameToID(this.name); + } + + getName() { + return this.get('name'); + } + + getDescription() { + return this.get('description'); + } + + getID() { + return this.id; + } + + + /** + * Normalize a glossary entry name into a unique id + * + * @param {String} + * @return {String} + */ + static nameToID(name) { + return slug(name); + } +} module.exports = GlossaryEntry; |