Class: SampleFile::Image

Inherits:
Base
  • Object
show all
Defined in:
lib/sample_file/image.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#file

Constructor Details

#initialize(type = 'png', opts = {}) ⇒ Image

Returns a new instance of Image.



7
8
9
10
11
# File 'lib/sample_file/image.rb', line 7

def initialize(type='png', opts={})
  @type = type
  @width  = opts[:width]  || opts[:height]
  @height = opts[:height] || opts[:width]
end

Instance Attribute Details

#heightObject (readonly)

Returns the value of attribute height.



5
6
7
# File 'lib/sample_file/image.rb', line 5

def height
  @height
end

#typeObject (readonly)

Returns the value of attribute type.



5
6
7
# File 'lib/sample_file/image.rb', line 5

def type
  @type
end

#widthObject (readonly)

Returns the value of attribute width.



5
6
7
# File 'lib/sample_file/image.rb', line 5

def width
  @width
end

Instance Method Details

#file_pathObject



13
14
15
16
17
18
19
# File 'lib/sample_file/image.rb', line 13

def file_path
  if width && height
    path_to_resized_image
  else
    path_to_base_image
  end
end

#tmpdirObject

Temporary directory where images will be stored



23
24
25
# File 'lib/sample_file/image.rb', line 23

def tmpdir
  @tmpdir ||= File.join(Dir.tmpdir, 'sample_file', 'image')
end