Class: GeneratedImage

Inherits:
Object
  • Object
show all
Defined in:
lib/jekyll-4-picture-tag/generated_image.rb

Overview

Generated Image Represents a generated source file.

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of GeneratedImage.



7
8
9
10
11
12
13
14
# File 'lib/jekyll-4-picture-tag/generated_image.rb', line 7

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

  @size = build_size(width)

  generate_image unless File.exist? absolute_filename
end

Instance Method Details

#absolute_filenameObject



23
24
25
# File 'lib/jekyll-4-picture-tag/generated_image.rb', line 23

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

#nameObject



16
17
18
19
20
21
# File 'lib/jekyll-4-picture-tag/generated_image.rb', line 16

def name
  name = @source.base_name
  name << "-#{@size[:width]}by#{@size[:height]}-"
  name << @source.digest
  name << '.' + @format
end

#widthObject



27
28
29
# File 'lib/jekyll-4-picture-tag/generated_image.rb', line 27

def width
  @size[:width]
end