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



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

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)


79
80
81
# File 'app/models/goldencobra/upload.rb', line 79

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

#titleObject



40
41
42
# File 'app/models/goldencobra/upload.rb', line 40

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

#unzip_filesObject



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

def unzip_files
  if self.image_file_name.include?(".zip") && File.exists?(self.image.path)
    require 'zip'
    zipped_files = Zip::File.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