Class: RMceUploadr::Image

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/rmce_uploadr/app/image.rb

Overview

This class expects the following table attributes to be found:

- +data_file_name+ (string)
- +data_content_type+ (string)
- +data_file_size+ (integer)
- +data_updated_at+ (datetime)
- +width+ (integer)
- +height+ (integer)

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#tempfileObject

set in images_controller needed to calcuate original file geometry in :update_image_geometry



16
17
18
# File 'lib/rmce_uploadr/app/image.rb', line 16

def tempfile
  @tempfile
end

Instance Method Details

#geometryObject

Returns a string with width and height e.g. “100x50”



22
23
24
25
# File 'lib/rmce_uploadr/app/image.rb', line 22

def geometry
  return "" if width.nil? || height.nil?
  "#{width}x#{height}"
end

#size_in_bytesObject

Convers image size in B, Kb, Mb or Gb and returns something like “10Kb”



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/rmce_uploadr/app/image.rb', line 29

def size_in_bytes
  case data_file_size
  when 0..1023
    "#{data_file_size}B"
  when 1024..1048575
    "#{(data_file_size / 1024.0).round}Kb"
  when 1048576..1073741823
    "#{(data_file_size / 1048576.0).round}Mb"
  else
    "#{(data_file_size / 1073741823.0).round}Gb"
  end
end