Module: Sunrise::Models::Asset::InstanceMethods
- Defined in:
- lib/sunrise/models/asset.rb
Instance Method Summary collapse
- #as_json(options = nil) ⇒ Object
- #format_created_at ⇒ Object
- #has_dimensions? ⇒ Boolean
- #image? ⇒ Boolean
- #thumb_url ⇒ Object
- #to_xml(options = {}, &block) ⇒ Object
Instance Method Details
#as_json(options = nil) ⇒ Object
52 53 54 55 56 57 58 59 60 |
# File 'lib/sunrise/models/asset.rb', line 52 def as_json( = nil) = { :only => [:id, :guid, :assetable_id, :assetable_type, :user_id, :data_file_size, :data_content_type], :root => 'asset', :methods => [:filename, :url, :thumb_url] }.merge( || {}) super end |
#format_created_at ⇒ Object
36 37 38 |
# File 'lib/sunrise/models/asset.rb', line 36 def format_created_at I18n.l(created_at, :format => "%d.%m.%Y %H:%M") end |
#has_dimensions? ⇒ Boolean
62 63 64 |
# File 'lib/sunrise/models/asset.rb', line 62 def has_dimensions? respond_to?(:width) && respond_to?(:height) end |
#image? ⇒ Boolean
66 67 68 |
# File 'lib/sunrise/models/asset.rb', line 66 def image? Sunrise::Utils::IMAGE_TYPES.include?(self.data_content_type) end |
#thumb_url ⇒ Object
32 33 34 |
# File 'lib/sunrise/models/asset.rb', line 32 def thumb_url data.thumb.url end |
#to_xml(options = {}, &block) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/sunrise/models/asset.rb', line 40 def to_xml( = {}, &block) = {:only => [:id], :root => 'asset'}.merge() [:procs] ||= Proc.new do |, record| [:builder].tag!('filename', filename) [:builder].tag!('path', url) [:builder].tag!('size', data_file_size) end super end |