requirementSources function

Map<String, String> requirementSources(
  1. String yamlText
)

The requirements of the Blueprint in yamlText, each with the text of its source and rationale values.

Implementation

Map<String, String> requirementSources(String yamlText) {
  final out = <String, String>{};
  void collect(Object? node, StringBuffer into) {
    if (node is! YamlMap) return;
    for (final e in node.entries) {
      final k = '${e.key}';
      if ((k == 'source' || k == 'rationale') && e.value is! YamlMap) {
        into.writeln('${e.value}');
      } else {
        collect(e.value, into);
      }
    }
  }

  void walk(Object? node) {
    if (node is! YamlMap) return;
    for (final e in node.entries) {
      final k = '${e.key}';
      if (_requirementLists.contains(k.split(' ').first)) {
        final list = e.value;
        if (list is! YamlMap) continue;
        for (final item in list.entries) {
          final id = '${item.key}'.split(' ').first;
          if (!id.contains('-REQU-') || id.endsWith('-LST')) continue;
          final b = StringBuffer();
          collect(item.value, b);
          out[id] = '$b';
        }
      } else {
        walk(e.value);
      }
    }
  }

  walk(loadYaml(yamlText));
  return out;
}