Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

12345678910111213141516171819202122232425262728293031323334353637
  1. 'use strict';
  2. var _ = require('lodash');
  3. /**
  4. * Choice object
  5. * Normalize input as choice object
  6. * @constructor
  7. * @param {Number|String|Object} val Choice value. If an object is passed, it should contains
  8. * at least one of `value` or `name` property
  9. */
  10. module.exports = class Choice {
  11. constructor(val, answers) {
  12. // Don't process Choice and Separator object
  13. if (val instanceof Choice || val.type === 'separator') {
  14. return val;
  15. }
  16. if (_.isString(val) || _.isNumber(val)) {
  17. this.name = String(val);
  18. this.value = val;
  19. this.short = String(val);
  20. } else {
  21. _.extend(this, val, {
  22. name: val.name || val.value,
  23. value: 'value' in val ? val.value : val.name,
  24. short: val.short || val.name || val.value
  25. });
  26. }
  27. if (_.isFunction(val.disabled)) {
  28. this.disabled = val.disabled(answers);
  29. } else {
  30. this.disabled = val.disabled;
  31. }
  32. }
  33. };