Class: LightResizer::Middleware::Path
- Inherits:
-
Object
- Object
- LightResizer::Middleware::Path
- Defined in:
- lib/light_resizer/middleware/path.rb
Constant Summary collapse
- PREFIX_REGEXP =
/^[0-9]+x[0-9]+(_crop|_convert)*_/
Instance Attribute Summary collapse
-
#request_path ⇒ Object
Returns the value of attribute request_path.
Instance Method Summary collapse
-
#convert_path? ⇒ Boolean
Bool returns true if image should be converted on resize.
-
#crop_path? ⇒ Boolean
Bool returns true if image should be croped on resize.
- #dimensions ⇒ Object
- #image_extension ⇒ Object
-
#image_path ⇒ Object
String last part of request – relative path.
-
#image_path? ⇒ Boolean
Bool returns true if request path begins with ‘image’.
-
#prefix ⇒ Object
String returns prefix of resized image name 200x200_crop_image.png => 200x200_crop.
Instance Attribute Details
#request_path ⇒ Object
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
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
22 23 24 |
# File 'lib/light_resizer/middleware/path.rb', line 22 def crop_path? prefix =~ /crop/ end |
#dimensions ⇒ Object
48 49 50 |
# File 'lib/light_resizer/middleware/path.rb', line 48 def dimensions prefix.split('_').first end |
#image_extension ⇒ Object
37 38 39 |
# File 'lib/light_resizer/middleware/path.rb', line 37 def image_extension File.extname(request_path) end |
#image_path ⇒ Object
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.('..', request_dir) File.join(dir, original_filename) end |
#image_path? ⇒ Boolean
Bool returns true if request path begins with ‘image’
16 17 18 |
# File 'lib/light_resizer/middleware/path.rb', line 16 def image_path? request_dir.end_with?('light_resize') end |
#prefix ⇒ Object
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 |