Class: PictureTag::GeneratedImage

Inherits:
Object
  • Object
show all
Defined in:
lib/jekyll_picture_tag/images/generated_image.rb

Overview

Represents a generated image, but not the file itself. Its purpose is to make its properties available for query, and hand them off to the ImageFile class for generation.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source_file:, width:, format:) ⇒ GeneratedImage

Returns a new instance of GeneratedImage.



10
11
12
13
14
# File 'lib/jekyll_picture_tag/images/generated_image.rb', line 10

def initialize(source_file:, width:, format:)
  @source = source_file
  @width  = width
  @raw_format = format
end

Instance Attribute Details

#widthObject (readonly)

Returns the value of attribute width.



8
9
10
# File 'lib/jekyll_picture_tag/images/generated_image.rb', line 8

def width
  @width
end

Instance Method Details

#absolute_filenameObject

/home/dave/my_blog/_site/generated/somefolder/myimage-100-123abc.jpg ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^



30
31
32
# File 'lib/jekyll_picture_tag/images/generated_image.rb', line 30

def absolute_filename
  @absolute_filename ||= File.join(PictureTag.dest_dir, name)
end

#exists?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/jekyll_picture_tag/images/generated_image.rb', line 20

def exists?
  File.exist?(absolute_filename)
end

#formatObject



16
17
18
# File 'lib/jekyll_picture_tag/images/generated_image.rb', line 16

def format
  @format ||= process_format(@raw_format)
end

#generateObject



24
25
26
# File 'lib/jekyll_picture_tag/images/generated_image.rb', line 24

def generate
  generate_image unless @source.missing || exists?
end

#nameObject

/home/dave/my_blog/_site/generated/somefolder/myimage-100-123abc.jpg ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^



36
37
38
# File 'lib/jekyll_picture_tag/images/generated_image.rb', line 36

def name
  @name ||= "#{@source.base_name}-#{@width}-#{id}.#{@format}"
end

#qualityObject



56
57
58
# File 'lib/jekyll_picture_tag/images/generated_image.rb', line 56

def quality
  PictureTag.quality(format, width)
end

#source_heightObject

Post crop



52
53
54
# File 'lib/jekyll_picture_tag/images/generated_image.rb', line 52

def source_height
  image.height
end

#source_widthObject

Post crop



47
48
49
# File 'lib/jekyll_picture_tag/images/generated_image.rb', line 47

def source_width
  image.width
end

#uriObject

https://example.com/assets/somefolder/myimage-100-123abc.jpg ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^



42
43
44
# File 'lib/jekyll_picture_tag/images/generated_image.rb', line 42

def uri
  ImgURI.new(name).to_s
end