aboutsummaryrefslogtreecommitdiff
path: root/src/pattern.js
diff options
context:
space:
mode:
authorDeterminant <ted.sybil@gmail.com>2019-01-30 00:58:11 -0500
committerDeterminant <ted.sybil@gmail.com>2019-01-30 00:58:11 -0500
commit00f036861c73f72f8863cbc2259b440ca1344df1 (patch)
treeb98450bf4f453bb79df7075336da9ccb5baed170 /src/pattern.js
parentd9720829424f01bedfd2edc5cb6682c820566a2b (diff)
re-organize the code
Diffstat (limited to 'src/pattern.js')
-rw-r--r--src/pattern.js24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/pattern.js b/src/pattern.js
new file mode 100644
index 0000000..ad94253
--- /dev/null
+++ b/src/pattern.js
@@ -0,0 +1,24 @@
+export class Pattern {
+ constructor(id, isRegex, value, label) {
+ this.id = id;
+ this.isRegex = isRegex;
+ this.value = value;
+ this.label = label;
+ }
+
+ get regex() { return new RegExp(this.isRegex ? this.value : `^${this.value}$`); }
+ get isEmpty() { return this.label === null; }
+ static emptyPattern = () => new Pattern(0, true, '', null);
+ static anyPattern = () => new Pattern('any', true, '.*', 'Any');
+}
+
+export class PatternEntry {
+ constructor(name, idx, calPattern, eventPattern) {
+ this.name = name;
+ this.idx = idx;
+ this.cal = calPattern;
+ this.event = eventPattern;
+ }
+
+ static defaultPatternEntry = (idx) => new PatternEntry('', idx, Pattern.emptyPattern(), Pattern.anyPattern());
+}