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

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

Instance Method Summary collapse

Instance Method Details

#as_json(options = nil) ⇒ Object



61
62
63
64
65
66
67
68
69
# File 'lib/sunrise/models/asset.rb', line 61

def as_json(options = nil)
  options = {
    :only => [:id, :guid, :assetable_id, :assetable_type, :user_id], 
    :root => 'asset', 
    :methods => [:filename, :url, :size, :content_type, :thumb_url]
  }.merge(options || {})
  
  super
end

#format_created_atObject



37
38
39
# File 'lib/sunrise/models/asset.rb', line 37

def format_created_at
  I18n.l(created_at, :format => "%d.%m.%Y %H:%M")
end

#geometryObject



79
80
81
82
# File 'lib/sunrise/models/asset.rb', line 79

def geometry
  @geometry ||= Paperclip::Geometry.from_file(data.to_file)
  @geometry
end

#has_dimensions?Boolean

Returns:

  • (Boolean)


71
72
73
# File 'lib/sunrise/models/asset.rb', line 71

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

#image?Boolean

Returns:

  • (Boolean)


75
76
77
# File 'lib/sunrise/models/asset.rb', line 75

def image?
  Sunrise::Utils::IMAGE_TYPES.include?(content_type)
end

#thumb_urlObject



33
34
35
# File 'lib/sunrise/models/asset.rb', line 33

def thumb_url
  url(:thumb)
end

#to_xml(options = {}, &block) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/sunrise/models/asset.rb', line 41

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', size)
    
    unless styles.empty?
      options[:builder].tag!('styles') do |xml|
        styles.each do |style|
          xml.tag!(style.first, url(style.first))
        end
      end
    end
  end
  
  super
end