Class: LlmTranslate::FileFinder
- Inherits:
-
Object
- Object
- LlmTranslate::FileFinder
- Defined in:
- lib/llm_translate/file_finder.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
Instance Method Summary collapse
- #ensure_output_directory(output_path) ⇒ Object
- #find_markdown_files ⇒ Object
-
#initialize(config, logger) ⇒ FileFinder
constructor
A new instance of FileFinder.
- #output_path_for(input_path) ⇒ Object
- #should_skip_file?(_input_path, output_path) ⇒ Boolean
Constructor Details
#initialize(config, logger) ⇒ FileFinder
11 12 13 14 |
# File 'lib/llm_translate/file_finder.rb', line 11 def initialize(config, logger) @config = config @logger = logger end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
9 10 11 |
# File 'lib/llm_translate/file_finder.rb', line 9 def config @config end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
9 10 11 |
# File 'lib/llm_translate/file_finder.rb', line 9 def logger @logger end |
Instance Method Details
#ensure_output_directory(output_path) ⇒ Object
68 69 70 71 72 73 74 |
# File 'lib/llm_translate/file_finder.rb', line 68 def ensure_output_directory(output_path) output_dir = File.dirname(output_path) return if Dir.exist?(output_dir) logger.debug "Creating output directory: #{output_dir}" FileUtils.mkdir_p(output_dir) end |
#find_markdown_files ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/llm_translate/file_finder.rb', line 16 def find_markdown_files input_dir = config.input_directory raise FileError, "Input directory does not exist: #{input_dir}" unless Dir.exist?(input_dir) logger.debug "Scanning directory: #{input_dir}" logger.debug "Include patterns: #{config.include_patterns}" logger.debug "Exclude patterns: #{config.exclude_patterns}" files = [] Find.find(input_dir) do |path| next if File.directory?(path) relative_path = Pathname.new(path).relative_path_from(Pathname.new(input_dir)).to_s # Skip if file doesn't match include patterns next unless matches_include_patterns?(relative_path) # Skip if file matches exclude patterns next if matches_exclude_patterns?(relative_path) # Skip if file is not readable unless File.readable?(path) logger.warn "Skipping unreadable file: #{path}" next end files << path logger.debug "Found markdown file: #{relative_path}" end logger.info "Found #{files.length} markdown files" files.sort end |
#output_path_for(input_path) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/llm_translate/file_finder.rb', line 52 def output_path_for(input_path) input_dir = Pathname.new(config.input_directory) output_dir = Pathname.new(config.output_directory) file_path = Pathname.new(input_path) # Get relative path from input directory relative_path = file_path.relative_path_from(input_dir) # Apply filename strategy output_filename = apply_filename_strategy(relative_path.basename.to_s) output_relative_path = relative_path.dirname + output_filename # Combine with output directory output_dir + output_relative_path end |
#should_skip_file?(_input_path, output_path) ⇒ Boolean
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/llm_translate/file_finder.rb', line 76 def should_skip_file?(_input_path, output_path) return false unless File.exist?(output_path) case config.overwrite_policy when 'skip' logger.info "Skipping existing file: #{output_path}" true when 'overwrite' false when 'backup' create_backup(output_path) false when 'ask' (output_path) else false end end |