<commit_before>class PageFile < ActiveRecord::Base

	FORMATS = {
		'audio/mpeg'      => :mp3,
		'image/gif'       => :gif,
		'image/jpeg'      => :jpg,
		'image/jpg'       => :jpg,
		'image/pjpeg'     => :jpg,
		'image/png'       => :png,
		'application/pdf' => :pdf
	}

	belongs_to :page
	belongs_to :binary, :dependent => :destroy
	
	validates_presence_of :binary_id
	
	acts_as_list :scope => :page

	acts_as_textable [ "description" ], :allow_any => false

	validate do |file|
		file.name = File.basename(file.filename, ".*") unless file.name?
		file.content_type = 'image/jpeg' if file.content_type == 'image/x-citrix-pjpeg' # Fuck you, Citrix
		file.content_type = 'image/jpeg' if file.content_type == 'image/pjpeg'          # Fuck you, MSIE
	end
	
	def file=(file)
		self.filename     = file.original_filename rescue File.basename( file.path )
		self.filesize     = file.size
		self.content_type = file.content_type
		self.binary       = Binary.create unless self.binary
		self.binary.data  = file.read
		self.binary.save
	end
	
	def data
		self.binary.data
	end
	
	def format?
		(self.content_type && FORMATS.keys.include?(self.content_type)) ? true : false
	end
	
	def format
		FORMATS[self.content_type]
	end<commit_msg>Citrix fix for GIF images<commit_after>class PageFile < ActiveRecord::Base

	FORMATS = {
		'audio/mpeg'      => :mp3,
		'image/gif'       => :gif,
		'image/jpeg'      => :jpg,
		'image/jpg'       => :jpg,
		'image/pjpeg'     => :jpg,
		'image/png'       => :png,
		'application/pdf' => :pdf
	}

	belongs_to :page
	belongs_to :binary, :dependent => :destroy
	
	validates_presence_of :binary_id
	
	acts_as_list :scope => :page

	acts_as_textable [ "description" ], :allow_any => false

	validate do |file|
		file.name = File.basename(file.filename, ".*") unless file.name?
		file.content_type = 'image/jpeg' if file.content_type == 'image/x-citrix-pjpeg' # Fuck you, Citrix
		file.content_type = 'image/gif'  if file.content_type == 'image/x-citrix-gif'   # Fuck you, Citrix
	end
	
	def file=(file)
		self.filename     = file.original_filename rescue File.basename( file.path )
		self.filesize     = file.size
		self.content_type = file.content_type
		self.binary       = Binary.create unless self.binary
		self.binary.data  = file.read
		self.binary.save
	end
	
	def data
		self.binary.data
	end
	
	def format?
		(self.content_type && FORMATS.keys.include?(self.content_type)) ? true : false
	end
	
	def format
		FORMATS[self.content_type]
	end
{'fraction_non_alphanumeric': 0.1343042071197411, 'fraction_numerical': 0.0008090614886731392, 'mean_word_length': 3.1844331641285955, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2722899', 'n_tokens_mistral': 966, 'n_tokens_neox': 884, 'n_words': 185}