Roadbound-BRR/lib/models/brr_metadata.dart

51 lines
1.4 KiB
Dart

class BRRMetadata {
final String route; // "Metropolitan_Line_Uxbridge"
final String date; // "21_09_2025"
final String location; // "Uxbridge Station"
final String controller; // "Benjamin Watt"
final String? sheetNumber;
BRRMetadata({
required this.route,
required this.date,
required this.location,
required this.controller,
this.sheetNumber,
});
factory BRRMetadata.fromSchedule(String scheduleText) {
// Extract metadata from schedule header
final routeMatch = RegExp(r"ROUTE\s+(\w+)").firstMatch(scheduleText);
final dateMatch =
RegExp(r"(\d{1,2})\s+(\d{1,2})\s+(\d{2})").firstMatch(scheduleText);
return BRRMetadata(
route: routeMatch?.group(1) ?? "Unknown",
date: dateMatch != null
? "${dateMatch.group(1)}_${dateMatch.group(2)}_20${dateMatch.group(3)}"
: DateTime.now().toString().split(" ")[0],
location: "Unknown",
controller: "Unknown",
);
}
Map<String, dynamic> toJson() {
return {
"route": route,
"date": date,
"location": location,
"controller": controller,
"sheetNumber": sheetNumber,
};
}
factory BRRMetadata.fromJson(Map<String, dynamic> json) {
return BRRMetadata(
route: json["route"] as String,
date: json["date"] as String,
location: json["location"] as String,
controller: json["controller"] as String,
sheetNumber: json["sheetNumber"] as String?,
);
}
}