Relation.fromFrontmatterString constructor

Relation.fromFrontmatterString(
  1. String source,
  2. String value
)

Decodes a compact frontmatter string.

Implementation

factory Relation.fromFrontmatterString(String source, String value) {
  final parts = value.split('|');
  final rawType = parts.isNotEmpty ? parts[0].trim() : '';
  final type = rawType.isEmpty ? RelationType.relatedTo : rawType;
  final target = parts.length > 1 ? parts[1].trim() : '';
  final weight = parts.length > 2
      ? double.tryParse(parts[2].trim()) ?? 1.0
      : 1.0;
  return Relation(source: source, target: target, type: type, weight: weight);
}