Sha256: 1fa3079614258f2afa28c588b1387ce00d3a28158aae467f0b4629f8423cdfec

Contents?: true

Size: 1.15 KB

Versions: 1

Compression:

Stored size: 1.15 KB

Contents

# frozen_string_literal: true

# lib/no_comments/remover.rb

require "no_comments/version"
require "no_comments/content_processor"

module NoComments
  class Remover
    def self.clean(file_path, audit: false)
      if File.directory?(file_path)
        Dir.glob("#{file_path}/**/*.rb").each do |file|
          process_file(file, audit: audit)
        end
      else
        process_file(file_path, audit: audit)
      end
    end

    def self.process_file(file_path, audit: false)
      validate_file_extension(file_path)
      content = File.read(file_path)

      processor = ContentProcessor.new
      cleaned_content, comments = processor.process(content)

      if audit
        print_audit(file_path, comments)
      else
        File.write(file_path, cleaned_content)
      end
    end

    def self.validate_file_extension(file_path)
      raise "Only Ruby files are supported" unless file_path.end_with?(".rb")
    end

    def self.print_audit(file_path, comments)
      return if comments.empty?

      puts "File: #{file_path}"
      comments.each do |line_number, comment_text|
        puts "  Line #{line_number}: #{comment_text}"
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
no_comments-0.1.6 lib/no_comments/remover.rb