applyTransformations method

Object applyTransformations(
  1. Object data,
  2. bool debug
)

Applies the relevant transformations based on the set fields and specified order

Implementation

Object applyTransformations(Object data, bool debug) {
  // Use specified transformation order or default order if not provided
  final List<TransformationType> order = transformationOrder ??
      [
        if (nth != null) TransformationType.nth,
        if (splitBy != null) TransformationType.splitBy,
        if (apply != null) TransformationType.apply,
        if (replaceFirst != null || replaceAll != null)
          TransformationType.replace,
        if (regexReplace != null || regexReplaceWith != null)
          TransformationType.regexReplace,
        if (regex != null || regexGroup != null)
          TransformationType.regexMatch,
        if (cropStart != null) TransformationType.cropStart,
        if (cropEnd != null) TransformationType.cropEnd,
        if (prepend != null) TransformationType.prepend,
        if (append != null) TransformationType.append,
        if (match != null) TransformationType.match,
      ];

  for (final TransformationType transformation in order) {
    switch (transformation) {
      case TransformationType.nth:
        final result = _nth(data, debug);
        if (result != null) {
          data = result;
        }
        break;

      case TransformationType.splitBy:
        final result = _splitBy(data, debug);
        if (result != null) {
          data = result;
        }
        break;

      case TransformationType.apply:
        final result = _apply(data, debug);
        if (result != null) {
          data = result;
        }
        break;

      case TransformationType.replace:
        final result = _replace(data, debug);
        if (result != null) {
          data = result;
        }
        break;

      case TransformationType.regexReplace:
        final result = _regexReplace(data, debug);
        if (result != null) {
          data = result;
        }
        break;

      case TransformationType.regexMatch:
        final result = _regexMatch(data, debug);
        if (result != null) {
          data = result;
        }
        break;

      case TransformationType.cropStart:
        final result = _cropStart(data, debug);
        if (result != null) {
          data = result;
        }
        break;

      case TransformationType.cropEnd:
        final result = _cropEnd(data, debug);
        if (result != null) {
          data = result;
        }
        break;

      case TransformationType.prepend:
        final result = _prepend(data, debug);
        if (result != null) {
          data = result;
        }
        break;

      case TransformationType.append:
        final result = _append(data, debug);
        if (result != null) {
          data = result;
        }
        break;

      case TransformationType.match:
        final result = _match(data, debug);
        if (result != null) {
          data = result;
        }
        break;
    }
  }

  return data;
}