Class: LightResizer::Middleware::Path

Inherits:
Object
  • Object
show all
Defined in:
lib/light_resizer/middleware/path.rb

Constant Summary collapse

PREFIX_REGEXP =
/^[0-9]+x[0-9]+(_crop|_convert)*_/

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#request_pathObject

Returns the value of attribute request_path.



8
9
10
# File 'lib/light_resizer/middleware/path.rb', line 8

def request_path
  @request_path
end

Instance Method Details

#convert_path?Boolean

Bool returns true if image should be converted on resize

Returns:

  • (Boolean)


27
28
29
# File 'lib/light_resizer/middleware/path.rb', line 27

def convert_path?
  prefix =~ /convert/
end

#crop_path?Boolean

Bool returns true if image should be croped on resize

Returns:

  • (Boolean)


22
23
24
# File 'lib/light_resizer/middleware/path.rb', line 22

def crop_path?
  prefix =~ /crop/
end

#dimensionsObject



48
49
50
# File 'lib/light_resizer/middleware/path.rb', line 48

def dimensions
  prefix.split('_').first
end

#image_extensionObject



37
38
39
# File 'lib/light_resizer/middleware/path.rb', line 37

def image_extension
  File.extname(request_path)
end

#image_pathObject

String last part of request – relative path



32
33
34
35
# File 'lib/light_resizer/middleware/path.rb', line 32

def image_path
  dir = File.expand_path('..', request_dir)
  File.join(dir, original_filename)
end

#image_path?Boolean

Bool returns true if request path begins with ‘image’

Returns:

  • (Boolean)


16
17
18
# File 'lib/light_resizer/middleware/path.rb', line 16

def image_path?
  request_dir.end_with?('light_resize')
end

#prefixObject

String returns prefix of resized image name 200x200_crop_image.png => 200x200_crop



44
45
46
# File 'lib/light_resizer/middleware/path.rb', line 44

def prefix
  filename[PREFIX_REGEXP].chop if image_path?
end