Class: PictureTag::SourceImage
- Inherits:
-
Object
- Object
- PictureTag::SourceImage
- Includes:
- MiniMagick
- Defined in:
- lib/jekyll_picture_tag/images/source_image.rb
Overview
Handles a given source image file and its properties. Provides a speed advantage by storing expensive file reads and writes in instance variables, to be reused by many different generated images.
Instance Attribute Summary collapse
-
#media_preset ⇒ Object
readonly
Returns the value of attribute media_preset.
-
#missing ⇒ Object
readonly
Returns the value of attribute missing.
-
#shortname ⇒ Object
readonly
Returns the value of attribute shortname.
Instance Method Summary collapse
-
#base_name ⇒ Object
/home/dave/my_blog/assets/images/somefolder/myimage.jpg ^^^^^^^^^^^^^^^^^^.
- #digest ⇒ Object
-
#ext ⇒ Object
/home/dave/my_blog/assets/images/somefolder/myimage.jpg ^^^.
- #height ⇒ Object
-
#initialize(relative_filename, media_preset = nil) ⇒ SourceImage
constructor
A new instance of SourceImage.
-
#name ⇒ Object
/home/dave/my_blog/assets/images/somefolder/myimage.jpg ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^.
- #width ⇒ Object
Constructor Details
#initialize(relative_filename, media_preset = nil) ⇒ SourceImage
Returns a new instance of SourceImage.
10 11 12 13 14 15 16 17 18 |
# File 'lib/jekyll_picture_tag/images/source_image.rb', line 10 def initialize(relative_filename, media_preset = nil) # /home/dave/my_blog/assets/images/somefolder/myimage.jpg # ^^^^^^^^^^^^^^^^^^^^^^ @shortname = relative_filename @media_preset = media_preset @missing = missing? check_cache end |
Instance Attribute Details
#media_preset ⇒ Object (readonly)
Returns the value of attribute media_preset.
6 7 8 |
# File 'lib/jekyll_picture_tag/images/source_image.rb', line 6 def media_preset @media_preset end |
#missing ⇒ Object (readonly)
Returns the value of attribute missing.
6 7 8 |
# File 'lib/jekyll_picture_tag/images/source_image.rb', line 6 def missing @missing end |
#shortname ⇒ Object (readonly)
Returns the value of attribute shortname.
6 7 8 |
# File 'lib/jekyll_picture_tag/images/source_image.rb', line 6 def shortname @shortname end |
Instance Method Details
#base_name ⇒ Object
/home/dave/my_blog/assets/images/somefolder/myimage.jpg
^^^^^^^^^^^^^^^^^^
40 41 42 |
# File 'lib/jekyll_picture_tag/images/source_image.rb', line 40 def base_name @shortname.delete_suffix File.extname(@shortname) end |
#digest ⇒ Object
20 21 22 |
# File 'lib/jekyll_picture_tag/images/source_image.rb', line 20 def digest @digest ||= cache[:digest] || '' end |
#ext ⇒ Object
/home/dave/my_blog/assets/images/somefolder/myimage.jpg
^^^
46 47 48 |
# File 'lib/jekyll_picture_tag/images/source_image.rb', line 46 def ext @ext ||= File.extname(name)[1..-1].downcase end |
#height ⇒ Object
28 29 30 |
# File 'lib/jekyll_picture_tag/images/source_image.rb', line 28 def height @height ||= cache[:height] || 999_999 end |
#name ⇒ Object
/home/dave/my_blog/assets/images/somefolder/myimage.jpg ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
34 35 36 |
# File 'lib/jekyll_picture_tag/images/source_image.rb', line 34 def name @name ||= File.join(PictureTag.source_dir, @shortname) end |
#width ⇒ Object
24 25 26 |
# File 'lib/jekyll_picture_tag/images/source_image.rb', line 24 def width @width ||= cache[:width] || 999_999 end |