Class: JekyllAutoThumbnails::Registry

Inherits:
Object
  • Object
show all
Defined in:
lib/jekyll-auto-thumbnails/registry.rb

Overview

Image requirement registry

Tracks images needing thumbnails and their required dimensions. Handles duplicate registrations by keeping the largest dimensions.

Instance Method Summary collapse

Constructor Details

#initializeRegistry

Initialize empty registry



10
11
12
# File 'lib/jekyll-auto-thumbnails/registry.rb', line 10

def initialize
  @entries = {}
end

Instance Method Details

#entriesHash

Get all registered entries

Returns:

  • (Hash)

    url => height:



52
53
54
# File 'lib/jekyll-auto-thumbnails/registry.rb', line 52

def entries
  @entries.dup
end

#register(url, width, height) ⇒ Object

Register an image with required dimensions

Parameters:

  • url (String)

    image URL

  • width (Integer, nil)

    required width

  • height (Integer, nil)

    required height



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/jekyll-auto-thumbnails/registry.rb', line 19

def register(url, width, height)
  existing = @entries[url]

  @entries[url] = if existing
                    # Update to max dimensions
                    {
                      width: [existing[:width], width].compact.max,
                      height: [existing[:height], height].compact.max
                    }
                  else
                    { width: width, height: height }
                  end
end

#registered?(url) ⇒ Boolean

Check if image is registered

Parameters:

  • url (String)

    image URL

Returns:

  • (Boolean)

    true if registered



37
38
39
# File 'lib/jekyll-auto-thumbnails/registry.rb', line 37

def registered?(url)
  @entries.key?(url)
end

#requirements_for(url) ⇒ Hash?

Get requirements for image

Parameters:

  • url (String)

    image URL

Returns:

  • (Hash, nil)

    height: or nil if not registered



45
46
47
# File 'lib/jekyll-auto-thumbnails/registry.rb', line 45

def requirements_for(url)
  @entries[url]&.dup
end