Class: Document
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Document
- Includes:
- SocialStream::Models::Object
- Defined in:
- app/models/document.rb
Class Method Summary collapse
-
.lookup_subtype_class(doc) ⇒ Object
Searches for the suitable class based on its mime type.
- .new(*args) ⇒ Object
Instance Method Summary collapse
-
#as_json(options) ⇒ Object
JSON, generic version for most documents.
-
#format ⇒ Object
#mime_type‘s symbol.
-
#mime_type ⇒ Object
The Mime::Type of this document’s file.
-
#mime_type_type_sym ⇒ Object
The type part of the #mime_type.
Class Method Details
.lookup_subtype_class(doc) ⇒ Object
Searches for the suitable class based on its mime type
40 41 42 43 44 45 46 |
# File 'app/models/document.rb', line 40 def lookup_subtype_class(doc) SocialStream::Documents.subtype_classes_mime_types.each_pair do |klass, mime_types| return klass.to_s.classify.constantize if mime_types.include?(doc.mime_type.to_sym) end nil end |
.new(*args) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'app/models/document.rb', line 24 def new(*args) # If already called from subtype, continue through the stack return super if self.name != "Document" doc = super return doc if doc.file_content_type.blank? if klass = lookup_subtype_class(doc) return klass.new *args end doc end |
Instance Method Details
#as_json(options) ⇒ Object
JSON, generic version for most documents
65 66 67 68 69 70 71 72 73 |
# File 'app/models/document.rb', line 65 def as_json() { :id => id, :title => title, :description => description, :author => .name, :src => URI.join([:helper].root_url, file.url).to_s } end |
#format ⇒ Object
#mime_type‘s symbol
60 61 62 |
# File 'app/models/document.rb', line 60 def format mime_type.to_sym end |
#mime_type ⇒ Object
The Mime::Type of this document’s file
50 51 52 |
# File 'app/models/document.rb', line 50 def mime_type Mime::Type.lookup(file_content_type) end |
#mime_type_type_sym ⇒ Object
The type part of the #mime_type
55 56 57 |
# File 'app/models/document.rb', line 55 def mime_type_type_sym mime_type.to_s.split('/').first.to_sym end |