Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 1 | /** |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 2 | * Object representing information |
| 3 | * about a match's layer annotation. |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 4 | */ |
| 5 | define(function () { |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 6 | var _AvailableRE = |
| 7 | new RegExp("^([^\/]+?)\/([^=]+?)(?:=(spans|rels|tokens))?$"); |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 8 | |
| 9 | return { |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 10 | /** |
| 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 Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 19 | create : function (foundry, layer, type) { |
| 20 | return Object.create(this)._init(foundry, layer, type); |
| 21 | }, |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 22 | |
| 23 | // Initialize Layer |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 24 | _init : function (foundry, layer, type) { |
| 25 | if (foundry === undefined) |
Akron | d67d45b | 2017-05-18 21:47:38 +0200 | [diff] [blame] | 26 | throw new Error("Missing parameters"); |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 27 | |
| 28 | if (layer === undefined) { |
Akron | d67d45b | 2017-05-18 21:47:38 +0200 | [diff] [blame] | 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 | }; |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 37 | } |
| 38 | else { |
Akron | d67d45b | 2017-05-18 21:47:38 +0200 | [diff] [blame] | 39 | this.foundry = foundry; |
| 40 | this.layer = layer; |
| 41 | this.type = type; |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 42 | }; |
| 43 | |
| 44 | if (this.type === undefined) |
Akron | d67d45b | 2017-05-18 21:47:38 +0200 | [diff] [blame] | 45 | this.type = 'tokens'; |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 46 | |
| 47 | return this; |
| 48 | } |
| 49 | }; |
| 50 | }); |
| 51 | |