yokutango-mobile-reader/lib/models/yokutango_entry.dart

75 lines
1.8 KiB
Dart
Raw Permalink Normal View History

2022-01-26 01:58:47 +01:00
part of 'data_entry.dart';
class YokutangoEntry extends DataEntry {
2022-01-26 00:25:07 +01:00
final List<JapaneseWord> japanese;
final List<NorwegianWord> norwegian;
const YokutangoEntry({required this.japanese, required this.norwegian});
YokutangoEntry.fromJson(Map<String, dynamic> json)
: japanese = (json['japanese'] as List)
.map((e) => JapaneseWord.fromJson(e))
.toList(),
norwegian = (json['norwegian'] as List)
.map((e) => NorwegianWord.fromJson(e))
.toList();
@override
String toString() {
return "${japanese.join(" ### ")} - ${norwegian.join(" ### ")}";
}
YokutangoEntry.empty()
: japanese = [JapaneseWord.empty()],
norwegian = [NorwegianWord.empty()];
}
class JapaneseWord {
final String word;
final String? romaji;
final List<String>? hints;
const JapaneseWord({
required this.word,
this.romaji,
this.hints,
});
JapaneseWord.fromJson(Map<String, dynamic> json)
: word = json['word'],
romaji = json['romaji'],
hints = (json['hints'] as List?)?.map((e) => e as String).toList();
@override
String toString() {
return word +
((romaji != null) ? "/$romaji" : "") +
((hints != null) ? " (${hints!.join(", ")})" : "");
}
JapaneseWord.empty()
: word = "",
romaji = "",
hints = [];
}
class NorwegianWord {
final String word;
final List<String>? hints;
const NorwegianWord({required this.word, this.hints});
NorwegianWord.fromJson(Map<String, dynamic> json)
: word = json['word'],
hints = (json['hints'] as List?)?.map((e) => e as String).toList();
@override
String toString() {
return word + ((hints != null) ? " (${hints!.join(", ")})" : "");
}
NorwegianWord.empty()
: word = "",
hints = [];
}