blob: 82b9bd3daeae2c594791f740ca2940ec1789c925 [file] [log] [blame]
Nils Diewald0e6992a2015-04-14 20:13:52 +00001/**
Nils Diewald7148c6f2015-05-04 15:07:53 +00002 * Object representing information
3 * about a match's layer annotation.
Nils Diewald0e6992a2015-04-14 20:13:52 +00004 */
5define(function () {
Nils Diewald7148c6f2015-05-04 15:07:53 +00006 var _AvailableRE =
7 new RegExp("^([^\/]+?)\/([^=]+?)(?:=(spans|rels|tokens))?$");
Nils Diewald0e6992a2015-04-14 20:13:52 +00008
9 return {
Nils Diewald7148c6f2015-05-04 15:07:53 +000010 /**
11 * Create new match information
12 * object for one layer.
13 *
14 * Alternatively pass a string as
15 * <tt>base/s=span</tt>
16 *
17 * @param foundry
18 */
Nils Diewald0e6992a2015-04-14 20:13:52 +000019 create : function (foundry, layer, type) {
20 return Object.create(this)._init(foundry, layer, type);
21 },
Nils Diewald7148c6f2015-05-04 15:07:53 +000022
23 // Initialize Layer
Nils Diewald0e6992a2015-04-14 20:13:52 +000024 _init : function (foundry, layer, type) {
25 if (foundry === undefined)
Akrond67d45b2017-05-18 21:47:38 +020026 throw new Error("Missing parameters");
Nils Diewald0e6992a2015-04-14 20:13:52 +000027
28 if (layer === undefined) {
Akrond67d45b2017-05-18 21:47:38 +020029 if (_AvailableRE.exec(foundry)) {
30 this.foundry = RegExp.$1;
31 this.layer = RegExp.$2;
32 this.type = RegExp.$3;
33 }
34 else {
35 throw new Error("Missing parameters");
36 };
Nils Diewald0e6992a2015-04-14 20:13:52 +000037 }
38 else {
Akrond67d45b2017-05-18 21:47:38 +020039 this.foundry = foundry;
40 this.layer = layer;
41 this.type = type;
Nils Diewald0e6992a2015-04-14 20:13:52 +000042 };
43
44 if (this.type === undefined)
Akrond67d45b2017-05-18 21:47:38 +020045 this.type = 'tokens';
Nils Diewald0e6992a2015-04-14 20:13:52 +000046
47 return this;
48 }
49 };
50});
51