Class: Wco::Photo

Inherits:
Object
  • Object
show all
Includes:
Mongoid::Document, Mongoid::Paperclip, Mongoid::Paranoia, Mongoid::Timestamps, Utils
Defined in:
app/models/wco/photo.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils

#export, included

Instance Attribute Details

#content_typeObject



64
65
66
# File 'app/models/wco/photo.rb', line 64

def content_type
  @content_type
end

#image_dataObject



64
65
66
# File 'app/models/wco/photo.rb', line 64

def image_data
  @image_data
end

#original_filenameObject



64
65
66
# File 'app/models/wco/photo.rb', line 64

def original_filename
  @original_filename
end

Instance Method Details

#decode_base64_imageObject



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'app/models/wco/photo.rb', line 65

def decode_base64_image
  if image_data && content_type && original_filename
    decoded_data = Base64.decode64(image_data)

    data = StringIO.new(decoded_data)
    data.class_eval do
      attr_accessor :content_type, :original_filename
    end

    data.content_type = content_type
    data.original_filename = File.basename(original_filename)

    self.photo = data
  end
end

#export_fieldsObject



54
55
56
57
58
59
60
61
# File 'app/models/wco/photo.rb', line 54

def export_fields
  %w|
    gallery_id
    name descr weight

    photo_file_name photo_content_type photo_file_size photo_updated_at photo_fingerprint
  |
end

#nameObject



19
20
21
22
23
24
# File 'app/models/wco/photo.rb', line 19

def name
  if !self[:name]
    update_attribute(:name, self.photo.to_s.split('/').last.split('?').first)
  end
  self[:name]
end