parse static method
Implementation
static VJournal parse(String vjournalString) {
final lines = vjournalString.split('\n');
String? uid;
DateTime? dtstamp;
String? summary;
String? description;
JOURNALStatus? status;
List<Attendee>? attendees;
MailTo? organizer;
String? contact;
for (var line in lines) {
final parts = line.split(':');
if (parts.length < 2) continue;
final key = parts[0];
final value = parts.getRange(1, parts.length).join(':');
switch (key) {
case 'UID':
uid = value;
break;
case 'DTSTAMP':
dtstamp = DateTime.parse(value.replaceAll('Z', ''));
break;
case 'SUMMARY':
summary = value;
break;
case 'DESCRIPTION':
description = value;
break;
case 'STATUS':
status = JOURNALStatus.values.firstWhere((e)=>Heplers.camelToSnake(e.name.replaceAll('_', '')).toUpperCase() == value);
break;
case 'ATTENDEE':
attendees ??= [];
attendees.add(Attendee.parse(value));
break;
case 'ORGANIZER':
organizer = MailTo(value);
break;
case 'CONTACT':
contact = value;
break;
}
}
return VJournal(
uid: uid ?? '',
dtstamp: dtstamp ?? DateTime.now(),
summary: summary ?? '',
description: description,
status: status,
attendees: attendees,
organizer: organizer,
contact: contact,
);
}