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:



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

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
# File 'lib/jekyll-auto-thumbnails/registry.rb', line 19

def register(url, width, height)
  previous = @entries[url]
  @entries[url] = {
    width: [previous&.dig(:width), width].compact.max,
    height: [previous&.dig(:height), height].compact.max
  }
end

#registered?(url) ⇒ Boolean

Check if image is registered

Parameters:

  • url (String)

    image URL

Returns:

  • (Boolean)

    true if registered



31
32
33
# File 'lib/jekyll-auto-thumbnails/registry.rb', line 31

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



39
40
41
# File 'lib/jekyll-auto-thumbnails/registry.rb', line 39

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