toGedcomString method

String toGedcomString({
  1. bool recursive = false,
})

Formats this element and optionally all of its subelements to GEDCOM string

Implementation

String toGedcomString({bool recursive = false}) {
  final buffer = StringBuffer();

  if (level >= 0) {
    buffer.write('$level');

    if (pointer != null && pointer!.isNotEmpty) {
      buffer.write(' $pointer');
    }

    buffer.write(' $tag');

    if (value != null && value!.isNotEmpty) {
      buffer.write(' $value');
    }

    buffer.write(crlf);
  }

  if (recursive) {
    for (final element in children) {
      buffer.write(element.toGedcomString(recursive: true));
    }
  }

  return buffer.toString();
}