/
Operator.ts
41 lines (32 loc) · 1.02 KB
/
Operator.ts
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
32
33
34
35
36
37
38
39
40
41
import {OnmsEnum, forLabel} from '../internal/OnmsEnum';
/**
* Represents a filter comparator.
* @module Comparator
*/
export class Operator extends OnmsEnum<number> {
/** Given a label ('and', 'or'), return the corresponding operator. */
public static forLabel(label: string) {
return forLabel(Operators, label);
}
/** Aliases for the command-line. */
private aliases = [] as string[];
constructor(id: number, label: string, ...aliases: string[]) {
super(id, label);
this.aliases = aliases;
}
/** Whether this comparator matches the given comparator string. */
public matches(comparator: string) {
return (comparator.toLowerCase() === this.label.toLowerCase())
|| this.aliases.indexOf(comparator) >= 0;
}
}
/* tslint:disable:object-literal-sort-keys */
const Operators = {
/** AND (all must match) */
AND: new Operator(1, 'AND'),
/** OR (at least one must match) */
OR: new Operator(2, 'OR'),
};
/** @hidden */
const frozen = Object.freeze(Operators);
export {frozen as Operators};