lib/cli/query-word: stringify
This commit is contained in:
@@ -1,5 +1,3 @@
|
||||
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:jadb/_data_ingestion/open_local_db.dart';
|
||||
@@ -38,8 +36,10 @@ class QueryWord extends Command {
|
||||
} else if (result.isEmpty) {
|
||||
print("No matches");
|
||||
} else {
|
||||
print(JsonEncoder.withIndent(' ')
|
||||
.convert(result.map((e) => e.toJson()).toList()));
|
||||
for (final e in result) {
|
||||
print(e.toString());
|
||||
print("");
|
||||
}
|
||||
}
|
||||
|
||||
print("Query took ${time.elapsedMilliseconds}ms");
|
||||
|
||||
@@ -80,4 +80,21 @@ class WordSearchResult {
|
||||
jlptLevel: JlptLevel.fromJson(json['jlptLevel'] as Object?),
|
||||
sources: WordSearchSources.fromJson(json['sources']),
|
||||
);
|
||||
|
||||
String _formatJapaneseWord(WordSearchRuby word) =>
|
||||
word.furigana == null ? word.base : "${word.base} (${word.furigana})";
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
final japaneseWord = _formatJapaneseWord(japanese[0]);
|
||||
final isCommonString = isCommon ? '(C)' : '';
|
||||
final jlptLevelString = "(${jlptLevel.toString()})";
|
||||
|
||||
return '''
|
||||
${score} | [$entryId] $japaneseWord $isCommonString $jlptLevelString
|
||||
Other forms: ${japanese.skip(1).map(_formatJapaneseWord).join(', ')}
|
||||
Senses: ${senses.map((s) => s.englishDefinitions).join(', ')}
|
||||
'''
|
||||
.trim();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user