read method

  1. @override
Future<String> read(
  1. String sampleName, {
  2. List<String> args = const [],
  3. Map<String, String> namedArgs = const {},
})
override

Implementation

@override
Future<String> read(
  String sampleName, {
  List<String> args = const [],
  Map<String, String> namedArgs = const {},
}) async {
  var content = (sampleMapping[sampleName] ?? ['']).join('\n');
  if (content.isEmpty) {
    throw const ReaderFailure(cause: 'target sample is empty');
  }
  for (var i = 0; i < args.length; i++) {
    content = content.replaceFirst('{*}', args[i]);
  }
  for (var i = 0; i < namedArgs.keys.length; i++) {
    content = content.replaceAll(
      '{${namedArgs.keys.elementAt(i)}}',
      namedArgs[namedArgs.keys.elementAt(i)] ?? '',
    );
  }
  return '$content\n';
}