Class: Goldencobra::Upload

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/goldencobra/upload.rb

Instance Method Summary collapse

Instance Method Details

#complete_list_nameObject



44
45
46
47
48
49
# File 'app/models/goldencobra/upload.rb', line 44

def complete_list_name
  result = ""
  result << "#{self.image_file_name} " if self.image_file_name.present?
  result << "(#{self.source}, #{self.rights}) " if self.source.present? || self.rights.present?
  result << "- #{self.updated_at.strftime("%d.%m.%Y - %H:%M Uhr")}"
end

#image_file?Boolean

Internal: Makes sure to only post-process files which are either pdf or image files. Word documents would break file upload.

No params

Returns true for image or pdf files and false for everything else

Returns:

  • (Boolean)


77
78
79
# File 'app/models/goldencobra/upload.rb', line 77

def image_file?
  !(self.image_content_type =~ /^image.*/).nil? || !(self.image_content_type =~ /pdf/).nil?
end

#titleObject



38
39
40
# File 'app/models/goldencobra/upload.rb', line 38

def title
  "#{self.image_file_name} (#{self.image_content_type})"
end

#unzip_filesObject



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'app/models/goldencobra/upload.rb', line 51

def unzip_files
  if self.image_file_name.include?(".zip") && File.exists?(self.image.path)
    require 'zip/zip'
    zipped_files = Zip::ZipFile.open(self.image.path)
    int = 0
    zipped_files.each do |zipped_file|
      int = int + 1
      if zipped_file.file?
        zipped_file.extract("tmp/#{self.id}_unzipped_#{int}.jpg")
        Goldencobra::Upload.create(:image => File.open("tmp/#{self.id}_unzipped_#{int}.jpg"),
                    :source => self.source,
                    :rights => self.rights,
                    :description => self.description,
                    :tag_list => self.tag_list.join(", ") )
        File.delete("tmp/#{self.id}_unzipped_#{int}.jpg")
      end
    end
  end
end