Files
jadb/lib/models/common/jlpt_level.dart

56 lines
1.1 KiB
Dart

enum JlptLevel implements Comparable<JlptLevel> {
none,
n1,
n2,
n3,
n4,
n5;
factory JlptLevel.fromString(String? level) {
switch (level?.toUpperCase()) {
case 'N1':
return JlptLevel.n1;
case 'N2':
return JlptLevel.n2;
case 'N3':
return JlptLevel.n3;
case 'N4':
return JlptLevel.n4;
case 'N5':
return JlptLevel.n5;
default:
return JlptLevel.none;
}
}
String? toNullableString() {
switch (this) {
case JlptLevel.n1:
return 'N1';
case JlptLevel.n2:
return 'N2';
case JlptLevel.n3:
return 'N3';
case JlptLevel.n4:
return 'N4';
case JlptLevel.n5:
return 'N5';
case JlptLevel.none:
return null;
}
}
int? get asInt =>
this == JlptLevel.none ? null : JlptLevel.values.indexOf(this);
String toString() => toNullableString() ?? 'N/A';
Object? toJson() => toNullableString();
factory JlptLevel.fromJson(Object? json) =>
JlptLevel.fromString(json as String?);
@override
int compareTo(JlptLevel other) => index - other.index;
}