-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOptions.js
More file actions
31 lines (23 loc) · 732 Bytes
/
Options.js
File metadata and controls
31 lines (23 loc) · 732 Bytes
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
'use strict';
var EventEmitter = require('events').EventEmitter;
function Options(group) {
EventEmitter.call(this);
this._group = typeof group === 'object' ? group : {};
}
Options.prototype = Object.create(EventEmitter.prototype);
Options.prototype.constructor = Options;
Options.prototype.list = function () {
return Object.keys(this._group);
};
Options.prototype.get = function (id) {
return this._group[id];
};
Options.prototype.select = function (id) {
var grupo = this.get(id); //utilizamos la funcion get de options para obtener el id de this.
if (grupo == undefined){
this.emit('choseError', 'option-does-not-exist', id);
}else {
this.emit('chose', id, grupo);
}
};
module.exports = Options;