From 8a86413fddddb4b3223532c487dfe36080bf9020 Mon Sep 17 00:00:00 2001 From: h7x4 Date: Mon, 15 Jun 2020 14:47:13 +0200 Subject: [PATCH] Fix some bugs --- lib/src/objects.dart | 19 ++++++++++++------- lib/src/unofficial_jisho_api_base.dart | 3 +-- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/lib/src/objects.dart b/lib/src/objects.dart index 248ae7d..8af0714 100644 --- a/lib/src/objects.dart +++ b/lib/src/objects.dart @@ -147,12 +147,12 @@ class KanjiResult { }; } - return { + var returnObject = { 'query': query, 'found': found, 'taughtIn': taughtIn, 'jlptLevel': jlptLevel, - 'newspaperFrequencyRank': newspaperFrequencyRank.toString(), + 'newspaperFrequencyRank': newspaperFrequencyRank.toString(), // TODO: Rewrite tests to make this value an int 'strokeCount': strokeCount, 'meaning': meaning, 'kunyomi': kunyomi, @@ -166,22 +166,27 @@ class KanjiResult { 'strokeOrderGifUri': strokeOrderGifUri, 'uri': uri }; + + if (newspaperFrequencyRank == null) returnObject.update('newspaperFrequencyRank', (value) => null); + returnObject.removeWhere((key, value) => value == null); + + return returnObject; } } class ExampleSentencePiece { - String unlifted; String lifted; + String unlifted; - ExampleSentencePiece({String unlifted, String lifted}){ - this.unlifted = unlifted; + ExampleSentencePiece({String lifted, String unlifted}){ this.lifted = lifted; + this.unlifted = unlifted; } Map toJson() { return { - 'unlifted': unlifted, - 'lifted': lifted + if (lifted != null) 'lifted': lifted, + if (unlifted != null)'unlifted': unlifted }; } } diff --git a/lib/src/unofficial_jisho_api_base.dart b/lib/src/unofficial_jisho_api_base.dart index 14307cb..2e71495 100644 --- a/lib/src/unofficial_jisho_api_base.dart +++ b/lib/src/unofficial_jisho_api_base.dart @@ -240,7 +240,6 @@ String uriForExampleSearch(String phrase) { ExampleResultData getKanjiAndKana(Element div) { final ul = div.querySelector('ul'); final contents = ul.children; - var kanji = ''; var kana = ''; @@ -270,7 +269,7 @@ ExampleResultData getKanjiAndKana(Element div) { kanji += unlifted; kana += unlifted; } - } else { + } else { // TODO: This doesn't catch the "。" when it's not in a tag final text = content.text.trim(); if (text != null) { kanji += text;