smartinteract/ts/smartinteract.classes.answerbucket.ts

34 lines
768 B
TypeScript
Raw Normal View History

2023-07-13 12:07:12 +00:00
import * as plugins from './smartinteract.plugins.js';
import { type IAnswerObject } from './smartinteract.classes.smartinteract.js';
2020-02-02 13:45:59 +00:00
/**
* class AnswerBucket holds answers
*/
export class AnswerBucket {
2020-08-31 19:23:51 +00:00
private answerMap = new plugins.lik.ObjectMap<IAnswerObject>();
2020-02-02 13:45:59 +00:00
/**
* add an answer to the bucket
*/
2020-02-02 18:05:50 +00:00
public addAnswer(answerArg: IAnswerObject) {
2020-02-02 13:45:59 +00:00
this.answerMap.add(answerArg);
}
/**
* gets an answer for a specific name
*/
2020-02-02 18:05:50 +00:00
public getAnswerFor(nameArg: string) {
2023-07-13 12:07:12 +00:00
const answer = this.answerMap.findSync((answerArg) => {
2020-02-02 13:45:59 +00:00
return answerArg.name === nameArg;
});
return answer ? answer.value : null;
}
/**
* gets all answers as array
*/
2020-02-02 18:05:50 +00:00
public getAllAnswers() {
2020-02-02 13:45:59 +00:00
return this.answerMap.getArray();
}
}