lib/cli/query-word: stringify
This commit is contained in:
@@ -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