<commit_before>class Resource < ActiveRecord::Base
  validates_uniqueness_of :filename
  after_destroy :delete_filename_on_disk
  before_validation_on_create :uniq_filename_on_disk
  belongs_to :article

  #Reads YAML file from config dir (iTunes.yml) for easy updating
  def get_itunes_categories
      itunes_categories_raw = YAML::load( File.open( "#{RAILS_ROOT}/config/iTunes.yml" ) )
      itunes_categories = []
      itunes_categories_raw.keys.sort.each do |cat|
        itunes_categories.push cat => itunes_categories_raw[cat]
      end
      return itunes_categories
  end

  def validate_on_update
    if itunes_explicit?
      errors.add_to_base("You must check the box to activate metadata.") unless itunes_metadata?
      errors.add_to_base("You must specify an author.") if itunes_author.blank?
      errors.add_to_base("You must specify an subtitle.") if itunes_subtitle.blank?
      errors.add_to_base("You must specify a summary.") if itunes_summary.blank?
      errors.add_to_base("You must specify keywords.") if itunes_keywords.blank?<commit_msg>Fixes a bug when trying to upload files via XMLRPC<commit_after>require 'tempfile'

class Resource < ActiveRecord::Base
  validates_uniqueness_of :filename
  after_destroy :delete_filename_on_disk
  before_validation_on_create :uniq_filename_on_disk
  belongs_to :article

  #Reads YAML file from config dir (iTunes.yml) for easy updating
  def get_itunes_categories
      itunes_categories_raw = YAML::load( File.open( "#{RAILS_ROOT}/config/iTunes.yml" ) )
      itunes_categories = []
      itunes_categories_raw.keys.sort.each do |cat|
        itunes_categories.push cat => itunes_categories_raw[cat]
      end
      return itunes_categories
  end

  def validate_on_update
    if itunes_explicit?
      errors.add_to_base("You must check the box to activate metadata.") unless itunes_metadata?
      errors.add_to_base("You must specify an author.") if itunes_author.blank?
      errors.add_to_base("You must specify an subtitle.") if itunes_subtitle.blank?
      errors.add_to_base("You must specify a summary.") if itunes_summary.blank?
      errors.add_to_base("You must specify keywords.") if itunes_keywords.blank?
{'fraction_non_alphanumeric': 0.0767473732297853, 'fraction_numerical': 0.0, 'mean_word_length': 4.354523227383863, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1839193', 'n_tokens_mistral': 689, 'n_tokens_neox': 676, 'n_words': 168}