input_assessment.js 794 B

12345678910111213141516171819202122232425262728293031
  1. import { Input } from './../io/input';
  2. import { LocalizedStrings } from '../services/localizedStringsService';
  3. export class InputAssessment extends Input {
  4. constructor (input_list) {
  5. super();
  6. this.index = 0;
  7. this.input_list = input_list.map((val) => {
  8. return {"value": val, "read": false};
  9. });
  10. }
  11. requestInput () {
  12. const promise = new Promise( (resolve, reject) => {
  13. if(this.index < this.input_list.length) {
  14. const input = this.input_list[this.index];
  15. input.read = true;
  16. this.index += 1;
  17. resolve(input.value);
  18. } else {
  19. reject(new Error(LocalizedStrings.getError("exceeded_input_request")));
  20. }
  21. });
  22. return promise
  23. }
  24. isInputAvailable () {
  25. return this.index < this.input_list.length;
  26. }
  27. }