From d65550a502a361e38448d68dcd8cf33de8430832 Mon Sep 17 00:00:00 2001 From: h7x4abk3g Date: Tue, 23 Jun 2020 11:48:32 +0200 Subject: [PATCH] Unify json null returns --- lib/src/exampleSearch.dart | 4 +- lib/src/objects.dart | 154 +++++++++++++++++-------------------- 2 files changed, 74 insertions(+), 84 deletions(-) diff --git a/lib/src/exampleSearch.dart b/lib/src/exampleSearch.dart index b0b8a11..f8eba01 100644 --- a/lib/src/exampleSearch.dart +++ b/lib/src/exampleSearch.dart @@ -24,7 +24,7 @@ List getChildrenAndSymbols(Element ul) { symbols += ulCharArray[offsetPointer]; offsetPointer++; } - final symbolElement = Element.html('' + symbols + ''); + final symbolElement = Element.html('${symbols}'); result.add(symbolElement); } offsetPointer += element.text.length; @@ -32,7 +32,7 @@ List getChildrenAndSymbols(Element ul) { } if (offsetPointer + 1 != ulText.length){ final symbols = ulText.substring(offsetPointer, ulText.length-1); - final symbolElement = Element.html('' + symbols + ''); + final symbolElement = Element.html('${symbols}'); result.add(symbolElement); } return result; diff --git a/lib/src/objects.dart b/lib/src/objects.dart index 62b8005..929204a 100644 --- a/lib/src/objects.dart +++ b/lib/src/objects.dart @@ -7,12 +7,11 @@ class YomiExample { String reading; String meaning; - YomiExample({String example, String reading, String meaning}) - { - this.example = example; - this.reading = reading; - this.meaning = meaning; - } + YomiExample({ + this.example, + this.reading, + this.meaning + }); Map toJson() => { @@ -28,11 +27,11 @@ class Radical { List forms; String meaning; - Radical({String symbol, List forms, String meaning}){ - this.symbol = symbol; - this.forms = forms; - this.meaning = meaning; - } + Radical({ + this.symbol, + this.forms, + this.meaning + }); Map toJson() => { @@ -63,16 +62,28 @@ class KanjiResult { String strokeOrderGifUri; String uri; + KanjiResult({ + this.query, + this.found, + this.taughtIn, + this.jlptLevel, + this.newspaperFrequencyRank, + this.strokeCount, + this.meaning, + this.kunyomi, + this.onyomi, + this.kunyomiExamples, + this.onyomiExamples, + this.radical, + this.parts, + this.strokeOrderDiagramUri, + this.strokeOrderSvgUri, + this.strokeOrderGifUri, + this.uri + }); + Map toJson() { - - if (found == false) { - return { - 'query': query, - 'found': found - }; - } - - var returnObject = { + return { 'query': query, 'found': found, 'taughtIn': taughtIn, @@ -84,15 +95,13 @@ class KanjiResult { 'onyomi': onyomi, 'onyomiExamples': onyomiExamples, 'kunyomiExamples': kunyomiExamples, - 'radical': radical.toJson(), + 'radical': (radical != null) ? radical.toJson() : null, 'parts': parts, 'strokeOrderDiagramUri': strokeOrderDiagramUri, 'strokeOrderSvgUri': strokeOrderSvgUri, 'strokeOrderGifUri': strokeOrderGifUri, 'uri': uri }; - - return returnObject; } } @@ -104,10 +113,10 @@ class ExampleSentencePiece { String lifted; String unlifted; - ExampleSentencePiece({String lifted, String unlifted}){ - this.lifted = lifted; - this.unlifted = unlifted; - } + ExampleSentencePiece({ + this.lifted, + this.unlifted + }); Map toJson() { return { @@ -123,12 +132,12 @@ class ExampleResultData { String english; List pieces; - ExampleResultData({String english, String kanji, String kana, List pieces}){ - this.english = english; - this.kanji = kanji; - this.kana = kana; - this.pieces = pieces; - } + ExampleResultData({ + this.english, + this.kanji, + this.kana, + this.pieces + }); Map toJson() { return { @@ -147,13 +156,13 @@ class ExampleResults { List results; String phrase; - ExampleResults({String query, bool found, List results, String uri, String phrase}){ - this.query = query; - this.found = found; - this.results = results; - this.uri = uri; - this.phrase = phrase; - } + ExampleResults({ + this.query, + this.found, + this.results, + this.uri, + this.phrase + }); Map toJson() { return { @@ -175,11 +184,11 @@ class PhraseScrapeSentence { String japanese; List pieces; - PhraseScrapeSentence ({String english, String japanese, List pieces}){ - this.english = english; - this.japanese = japanese; - this.pieces = pieces; - } + PhraseScrapeSentence ({ + this.english, + this.japanese, + this.pieces + }); Map toJson() => { 'english': english, @@ -197,21 +206,13 @@ class PhraseScrapeMeaning { List tags; PhraseScrapeMeaning({ - List seeAlsoTerms, - List sentences, - String definition, - List supplemental, - String definitionAbstract, - List tags, - }){ - this.seeAlsoTerms = seeAlsoTerms; - this.sentences = sentences; - this.definition = definition; - this.supplemental = supplemental; - this.definitionAbstract = definitionAbstract; - this.tags = tags; - - } + this.seeAlsoTerms, + this.sentences, + this.definition, + this.supplemental, + this.definitionAbstract, + this.tags + }); Map toJson() => { 'seeAlsoTerms': seeAlsoTerms, @@ -228,12 +229,9 @@ class KanjiKanaPair { String kana; KanjiKanaPair({ - String kanji, - String kana - }){ - this.kanji = kanji; - this.kana = kana; - } + this.kanji, + this.kana + }); Map toJson() => { 'kanji': kanji, @@ -251,22 +249,14 @@ class PhrasePageScrapeResult { List notes; PhrasePageScrapeResult({ - bool found, - String query, - String uri, - List tags, - List meanings, - List otherForms, - List notes, - }){ - this.found = found; - this.query = query; - this.uri = uri; - this.tags = tags; - this.meanings = meanings; - this.otherForms = otherForms; - this.notes = notes; - } + this.found, + this.query, + this.uri, + this.tags, + this.meanings, + this.otherForms, + this.notes + }); Map toJson() => {