From e50d4a9c1a3c4e38e3453a084f226c2448a5dff2 Mon Sep 17 00:00:00 2001 From: "Ian A. Cook" <6866411+nai888@users.noreply.github.com> Date: Mon, 31 Dec 2018 10:46:48 -0600 Subject: [PATCH] Refactor application of changes. Find multicharacter variable assignment error in categories. --- src/routes/Morph/MorphService.js | 40 ++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/src/routes/Morph/MorphService.js b/src/routes/Morph/MorphService.js index 0da96c81..85de99e6 100644 --- a/src/routes/Morph/MorphService.js +++ b/src/routes/Morph/MorphService.js @@ -15,6 +15,7 @@ class MorphService { this.splitCategories = this.splitCategories.bind(this) this.splitRewriteRules = this.splitRewriteRules.bind(this) this.splitSoundChanges = this.splitSoundChanges.bind(this) + this.applyChanges = this.applyChanges.bind(this) this.idChanged = this.idChanged.bind(this) this.morph = this.morph.bind(this) } @@ -142,6 +143,13 @@ class MorphService { // If the string wasn't split at all, it was missing a = errors.push(`The category ${cats[i]} is missing an = sign.`) } + } else if (split[0].length > 1) { + // If the string to the left of the = is more than one character + errors.push( + `The category ${ + cats[i] + } needs to be assigned to a single-character variable.` + ) } else { // Split the variable from its assignments assignments.push(split) @@ -252,6 +260,21 @@ class MorphService { return errors.length ? errors : splitChanges } + applyChanges (cats, rules, changes, lexicon, rwOutput) { + let results = [ + { + input: 'lector', + output: 'leitor' + }, + { + input: 'doctor', + output: 'doutor' + } + ] + + return results + } + idChanged (data, results) { const newResults = JSON.parse(JSON.stringify(results)) @@ -291,16 +314,13 @@ class MorphService { allErrors = allErrors.concat(soundChanges) if (allErrors.length) return allErrors - let results = [ - { - input: 'lector', - output: 'leitor' - }, - { - input: 'doctor', - output: 'doutor' - } - ] + const results = this.applyChanges( + categories, + rewriteRules, + soundChanges, + newData.lexicon, + newData.rewriteOutput + ) return this.idChanged(newData, results) }