Class: Tahweel::CLI::FileCollector

Inherits:
Object
  • Object
show all
Defined in:
lib/tahweel/cli/file_collector.rb

Overview

Collects files for processing from a given input path.

This utility class handles the logic of discovering files to process. It supports both single file paths and directory recursion.

Constant Summary collapse

SUPPORTED_EXTENSIONS =
%w[pdf jpg jpeg png].freeze

Class Method Summary collapse

Class Method Details

.collect(input_path, extensions: nil) ⇒ Array<String>

Collects files from the input path based on supported or provided extensions.

If the input path is a directory, it performs a recursive case-insensitive glob search for files matching the specified extensions.

If the input path is a file, it returns it as a single-element array, assuming the user explicitly wants to process it regardless of extension.



24
25
26
27
28
29
30
# File 'lib/tahweel/cli/file_collector.rb', line 24

def self.collect(input_path, extensions: nil)
  return [input_path] unless File.directory?(input_path)

  extensions ||= SUPPORTED_EXTENSIONS
  glob_pattern = File.join(input_path, "**", "*.{#{extensions.join(",")}}")
  Dir.glob(glob_pattern, File::FNM_CASEFOLD).sort
end