shouldExtractString method

bool shouldExtractString(
  1. DetectedString detectedString
)

Ask user if a string should be extracted

Implementation

bool shouldExtractString(DetectedString detectedString) {
  // Check if user already said to skip similar patterns
  if (_skipPatterns.contains(detectedString.context)) {
    return false;
  }

  // Show information about the string
  stdout.writeln('');
  stdout.writeln('Found: "${detectedString.value}"');
  stdout.writeln('Context: ${detectedString.context}');
  stdout.writeln('Confidence: ${detectedString.confidence}%');
  stdout.writeln('Snippet: ${_truncate(detectedString.snippet, 60)}');
  stdout.writeln('');

  // Create prompt
  final choice = Select(
    prompt: 'Extract this string?',
    options: ['Yes', 'No', 'Skip all similar'],
  ).interact();

  switch (choice) {
    case 0: // Yes
      return true;
    case 1: // No
      return false;
    case 2: // Skip all similar
      _skipPatterns.add(detectedString.context);
      return false;
    default:
      return false;
  }
}