Class: Document

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
SocialStream::Models::Object
Defined in:
app/models/document.rb

Direct Known Subclasses

Audio, Picture, Video

Constant Summary collapse

IMAGE_FORMATS =
["doc","ppt","xls","rar","zip","mpeg","plain","pdf"]

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.new(*args) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'app/models/document.rb', line 29

def new(*args)
  if !(self.name == "Document")
    return super
   end 
  doc = super
  
  if(doc.file_content_type.nil?)
    return doc
  end
  
  if !(doc.file_content_type =~ /^image.*/).nil?
    return Picture.new *args
  end
  
  if !(doc.file_content_type =~ /^audio.*/).nil?
    return Audio.new *args
  end
  
  if !(doc.file_content_type =~ /^video.*/).nil?
    return Video.new *args
  end
  
  return doc
end

Instance Method Details

#formatObject



59
60
61
# File 'app/models/document.rb', line 59

def format
  mime_type.to_sym
end

#mime_typeObject



55
56
57
# File 'app/models/document.rb', line 55

def mime_type
  Mime::Type.lookup(file_content_type)
end

#thumb(size, helper) ⇒ Object

Thumbnail file



64
65
66
67
68
69
70
# File 'app/models/document.rb', line 64

def thumb(size, helper)
  if format && IMAGE_FORMATS.include?(format.to_s)
    "#{ size.to_s }/#{ format }.png"
  else
    "#{ size.to_s }/default.png"
  end
end