Module: Sunrise::Models::Asset::InstanceMethods

Defined in:
lib/sunrise/models/asset.rb

Instance Method Summary collapse

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(options = nil)
  options = {
    :only => [:id, :guid, :assetable_id, :assetable_type, :user_id, :data_file_size, :data_content_type], 
    :root => 'asset',
    :methods => [:filename, :url, :thumb_url]
  }.merge(options || {})
  
  super
end

#format_created_atObject



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

Returns:

  • (Boolean)


62
63
64
# File 'lib/sunrise/models/asset.rb', line 62

def has_dimensions?
  respond_to?(:width) && respond_to?(:height)
end

#image?Boolean

Returns:

  • (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_urlObject



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(options = {}, &block)
  options = {:only => [:id], :root => 'asset'}.merge(options)
  
  options[:procs] ||= Proc.new do |options, record| 
    options[:builder].tag!('filename', filename)
    options[:builder].tag!('path', url)
    options[:builder].tag!('size', data_file_size)
  end
  
  super
end