parse static method

VAlarm parse(
  1. String valarmString
)

Implementation

static VAlarm parse(String valarmString) {
  final lines = valarmString.split('\n');
  VAlarmAction? action;
  Trriger? trigger;
  String? description;
  String? duration;
  int? repeat;
  String? attach;

  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 'ACTION':
        action = VAlarmAction.values.firstWhere((e)=> Heplers.camelToSnake(e.name).toUpperCase() == value);
        break;
      case 'TRIGGER':
        trigger = Trriger.parse(value);
        break;
      case 'DESCRIPTION':
        description = value;
        break;
      case 'DURATION':
        duration = value;
        break;
      case 'REPEAT':
        repeat = int.tryParse(value);
        break;
      case 'ATTACH':
        attach = value;
        break;
    }
  }

  if (action == null || trigger == null) {
    throw ArgumentError("ACTION and TRIGGER are required for a VALARM.");
  }

  return VAlarm(
    action: action,
    trigger: trigger,
    description: description,
    duration: duration,
    repeat: repeat,
    attach: attach,
  );
}