|
1 | 1 | "use strict"; |
2 | 2 | var cleanup_1 = require('./cleanup'); |
| 3 | +var Match = require('./matchers'); |
3 | 4 | function addToTasks(result, line, index) { |
4 | 5 | var action = line.slice(1).split('(')[0]; |
5 | 6 | var value = cleanup_1.trimQuotes(/\((.*?)\)$/.exec(line)[1]); |
6 | 7 | var task = result.chapters[index.chapter].pages[index.page].tasks[index.task]; |
| 8 | + var actionValue = Match.isAction(line)[2]; |
| 9 | + var isActionArray = Match.isArray(cleanup_1.trimQuotes(actionValue)); |
7 | 10 | switch (action) { |
8 | 11 | case 'test': |
9 | 12 | if (result.chapters[index.chapter].pages[index.page].tasks[index.task].tests === undefined) { |
10 | 13 | result.chapters[index.chapter].pages[index.page].tasks[index.task].tests = []; |
11 | 14 | } |
12 | | - result.chapters[index.chapter].pages[index.page].tasks[index.task].tests.push(value); |
| 15 | + if (!!isActionArray) { |
| 16 | + var valueList = actionValue.slice(1, -1).split(','); |
| 17 | + valueList.forEach(function (value) { |
| 18 | + value = cleanup_1.trimQuotes(value.trim()); |
| 19 | + result.chapters[index.chapter].pages[index.page].tasks[index.task].tests.push(value); |
| 20 | + }); |
| 21 | + } |
| 22 | + else { |
| 23 | + result.chapters[index.chapter].pages[index.page].tasks[index.task].tests.push(value); |
| 24 | + } |
13 | 25 | break; |
14 | 26 | case 'action': |
15 | | - var task_1 = result.chapters[index.chapter].pages[index.page].tasks[index.task]; |
16 | | - if (task_1.actions === undefined) { |
| 27 | + if (task.actions === undefined) { |
17 | 28 | result.chapters[index.chapter].pages[index.page].tasks[index.task].actions = []; |
18 | 29 | } |
19 | | - result.chapters[index.chapter].pages[index.page].tasks[index.task].actions.push(value); |
| 30 | + if (!!isActionArray) { |
| 31 | + var arrayOfActions = JSON.parse(isActionArray); |
| 32 | + arrayOfActions.forEach(function (value) { |
| 33 | + result.chapters[index.chapter].pages[index.page].tasks[index.task].actions.push(value); |
| 34 | + }); |
| 35 | + } |
| 36 | + else { |
| 37 | + result.chapters[index.chapter].pages[index.page].tasks[index.task].actions.push(value); |
| 38 | + } |
20 | 39 | return result; |
21 | 40 | break; |
22 | 41 | case 'hint': |
23 | | - if (task_1.hints === undefined) { |
| 42 | + if (task.hints === undefined) { |
24 | 43 | result.chapters[index.chapter].pages[index.page].tasks[index.task].hints = []; |
25 | 44 | } |
26 | | - result.chapters[index.chapter].pages[index.page].tasks[index.task].hints.push(value); |
| 45 | + if (!!isActionArray) { |
| 46 | + var valueList = actionValue.slice(1, -1).split(','); |
| 47 | + valueList.forEach(function (value) { |
| 48 | + value = cleanup_1.trimQuotes(value.trim()); |
| 49 | + result.chapters[index.chapter].pages[index.page].tasks[index.task].hints.push(value); |
| 50 | + }); |
| 51 | + } |
| 52 | + else { |
| 53 | + result.chapters[index.chapter].pages[index.page].tasks[index.task].hints.push(value); |
| 54 | + } |
27 | 55 | break; |
28 | 56 | default: |
29 | 57 | console.log('Invalid task action'); |
30 | 58 | } |
31 | 59 | return result; |
32 | 60 | } |
33 | | -exports.addToTasks = addToTasks; |
| 61 | +Object.defineProperty(exports, "__esModule", { value: true }); |
| 62 | +exports.default = addToTasks; |
0 commit comments