<commit_before>require "backupcp/version"

module Backupcp extend self
  def replace_files_with_backup files,destdir
    raise "destdir is not a directory" unless File.directory? destdir

    files.select{|f| File.exists? f}.each do |f|
      base = File.basename f
      target = File.join [destdir, base]
      FileUtils.move target, "#{target}.original" if File.exists? target
      FileUtils.copy f, target
    end
  end

  def replace_dir_with_backup fromdir,destdir
    raise "fromdir is not a directory" unless File.directory? fromdir
    raise "destdir is not a directory" unless File.directory? destdir

    replace_files_with_backup Dir.glob(File.join [fromdir, '*']).to_a, destdir
  end

  def replace_with_backup from, dest
    case from.class.to_s
    when "Array" then replace_files_with_backup from, dest
    when "String" then replace_dir_with_backup from, dest
    else raise "invalid argument type"
    end
  end

  def help
    puts <<-EOS.gsub(/^\s+/, "")
      backupcp file1 [, file2, ...] destdir
      backupcp fromdir destdir
    EOS
    exit
  end
end
<commit_msg>improve case branch by class<commit_after>require "backupcp/version"

module Backupcp extend self
  def replace_files_with_backup files,destdir
    raise "destdir is not a directory" unless File.directory? destdir

    files.select{|f| File.exists? f}.each do |f|
      base = File.basename f
      target = File.join [destdir, base]
      FileUtils.move target, "#{target}.original" if File.exists? target
      FileUtils.copy f, target
    end
  end

  def replace_dir_with_backup fromdir,destdir
    raise "fromdir is not a directory" unless File.directory? fromdir
    raise "destdir is not a directory" unless File.directory? destdir

    replace_files_with_backup Dir.glob(File.join [fromdir, '*']).to_a, destdir
  end

  def replace_with_backup from, dest
    case from
    when Array then replace_files_with_backup from, dest
    when String then replace_dir_with_backup from, dest
    else raise "invalid argument type"
    end
  end

  def help
    puts <<-EOS.gsub(/^\s+/, "")
      backupcp file1 [, file2, ...] destdir
      backupcp fromdir destdir
    EOS
    exit
  end
end

{'fraction_non_alphanumeric': 0.08256880733944955, 'fraction_numerical': 0.001834862385321101, 'mean_word_length': 3.2848722986247543, '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': '6765149', 'n_tokens_mistral': 691, 'n_tokens_neox': 676, 'n_words': 220}