blob: 0812f71c5dbdbafa39d3402c742cccbf4e4e4c8c [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)
26 throw new Error("Missing parameters");
27
28 if (layer === undefined) {
29 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 };
37 }
38 else {
39 this.foundry = foundry;
40 this.layer = layer;
41 this.type = type;
42 };
43
44 if (this.type === undefined)
45 this.type = 'tokens';
46
47 return this;
48 }
49 };
50});
51