<commit_before>class LegalDocument < ActiveRecord::Base
  include Versions # version/legal_document_version.rb
  belongs_to :documentable, polymorphic: true

  TYPES = %w(pdf bdoc ddoc zip rar gz tar 7z)

  attr_accessor :body

  before_save :save_to_filesystem
  def save_to_filesystem
    loop do
      rand = SecureRandom.random_number.to_s.last(4)
      next if rand.to_i == 0 || rand.length < 4
      self.path = "#{ENV['legal_documents_dir']}/#{Time.zone.now.to_formatted_s(:number)}_#{rand}.#{document_type}"
      break unless File.file?(path)
    end

    File.open(path, 'wb') { |f| f.write(Base64.decode64(body)) } unless Rails.env.test?
    self.path = path
  end
end<commit_msg>Added new legal doc types #2607<commit_after>class LegalDocument < ActiveRecord::Base
  include Versions # version/legal_document_version.rb
  belongs_to :documentable, polymorphic: true

  TYPES = %w(pdf bdoc ddoc zip rar gz tar 7z odt doc docx)

  attr_accessor :body

  before_save :save_to_filesystem
  def save_to_filesystem
    loop do
      rand = SecureRandom.random_number.to_s.last(4)
      next if rand.to_i == 0 || rand.length < 4
      self.path = "#{ENV['legal_documents_dir']}/#{Time.zone.now.to_formatted_s(:number)}_#{rand}.#{document_type}"
      break unless File.file?(path)
    end

    File.open(path, 'wb') { |f| f.write(Base64.decode64(body)) } unless Rails.env.test?
    self.path = path
  end
end
{'fraction_non_alphanumeric': 0.11960368011323426, 'fraction_numerical': 0.014154281670205236, 'mean_word_length': 3.926829268292683, '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': '747269', 'n_tokens_mistral': 517, 'n_tokens_neox': 494, 'n_words': 109}