<commit_before>module Squatch
  module Base
    class << self

      require 'fileutils'

      def squatch(options)

        destination_path = Dir.open(File.dirname(options[:data]))

        case File.ftype(options[:data])
        when 'file'
          files_to_squatch = Array[options[:data]]
          backup_dir = "#{File.dirname(options[:data])}/backup"
        when 'directory'
          files_to_squatch = Dir.glob("#{options[:data]}/**/*#{options[:ext]}")
          backup_dir = "#{options[:data]}/backup"
        else
          puts "Oops!"
          exit
        end

        Dir.exists?(backup_dir) ? true : Dir.mkdir(backup_dir)
        
        # squatch each file in files_to_compress and save in place
        begin
          files_to_squatch.each do |path|            
            File.open("#{path}", 'r+') do |file|
              
              FileUtils.copy_file(file, "#{backup_dir}/#{File.basename(file, File.extname(file))}.txt")
              puts "Backup of #{File.basename(file)} created at #{backup_dir} named #{File.basename(file, File.extname(file))}.txt."
              
              new_lines = ''

              puts "Squatching: #{File.basename(file)}..."
              file.each_line do |line|
                new_lines.concat(line.strip)
              end

              puts "LINES: #{new_lines}"

              new_lines.gsub!(';', '; ')
              new_lines.gsub!('{', '{ ')
              new_lines.gsub!('}', "}\n")
              new_lines.gsub!('/*', "\n/*")
              new_lines.gsub!('*/', "*/\n")

              # new_lines.each_char do |char|
              #   case char<commit_msg>master - NEW: removing puts<commit_after>module Squatch
  module Base
    class << self

      require 'fileutils'

      def squatch(options)

        destination_path = Dir.open(File.dirname(options[:data]))

        case File.ftype(options[:data])
        when 'file'
          files_to_squatch = Array[options[:data]]
          backup_dir = "#{File.dirname(options[:data])}/backup"
        when 'directory'
          files_to_squatch = Dir.glob("#{options[:data]}/**/*#{options[:ext]}")
          backup_dir = "#{options[:data]}/backup"
        else
          puts "Oops!"
          exit
        end

        Dir.exists?(backup_dir) ? true : Dir.mkdir(backup_dir)
        
        # squatch each file in files_to_compress and save in place
        begin
          files_to_squatch.each do |path|            
            File.open("#{path}", 'r+') do |file|
              
              FileUtils.copy_file(file, "#{backup_dir}/#{File.basename(file, File.extname(file))}.txt")
              puts "Backup of #{File.basename(file)} created at #{backup_dir} named #{File.basename(file, File.extname(file))}.txt."
              
              new_lines = ''

              puts "Squatching: #{File.basename(file)}..."
              file.each_line do |line|
                new_lines.concat(line.strip)
              end

              new_lines.gsub!(';', '; ')
              new_lines.gsub!('{', '{ ')
              new_lines.gsub!('}', "}\n")
              new_lines.gsub!('/*', "\n/*")
              new_lines.gsub!('*/', "*/\n")

              # new_lines.each_char do |char|
              #   case char
{'fraction_non_alphanumeric': 0.15308641975308643, 'fraction_numerical': 0.0, 'mean_word_length': 1.755952380952381, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4781211', 'n_tokens_mistral': 987, 'n_tokens_neox': 970, 'n_words': 177}