Module: Fontisan::Tables::Registry

Defined in:
lib/fontisan/tables/registry.rb

Overview

Single source of truth mapping OpenType table tags to Ruby classes.

Each table class registers itself via register_tag:

module Fontisan::Tables
class Hvar < Binary::BaseRecord
  register_tag "HVAR"
  ...
end
end

Dispatch sites use Tables::Registry.for(tag) instead of a case tag when "HVAR" switch. This is OCP-compliant: adding a new table means adding one register_tag line in the table's file, not editing every dispatch site.

Class Method Summary collapse

Class Method Details

.__clear__Object

Clear all registrations (testing only).



55
56
57
58
# File 'lib/fontisan/tables/registry.rb', line 55

def __clear__
  @by_tag.clear
  @by_class.clear
end

.for(tag) ⇒ Class?

Look up the table class for a tag.

Parameters:

  • tag (String)

    Four-byte OpenType table tag.

Returns:

  • (Class, nil)

    The table class, or nil if unknown.



37
38
39
# File 'lib/fontisan/tables/registry.rb', line 37

def for(tag)
  @by_tag[tag]
end

.register(tag, klass) ⇒ Object

Parameters:

  • tag (String)

    Four-byte OpenType table tag (e.g., "HVAR").

  • klass (Class)

    The Ruby class implementing the table.



28
29
30
31
# File 'lib/fontisan/tables/registry.rb', line 28

def register(tag, klass)
  @by_tag[tag] = klass
  @by_class[klass] = tag
end

.tag_for(klass) ⇒ String?

Reverse lookup: tag for a given class.

Parameters:

  • klass (Class)

    A table class.

Returns:

  • (String, nil)

    The tag, or nil if not registered.



45
46
47
# File 'lib/fontisan/tables/registry.rb', line 45

def tag_for(klass)
  @by_class[klass]
end

.tagsArray<String>

Returns All registered tags.

Returns:

  • (Array<String>)

    All registered tags.



50
51
52
# File 'lib/fontisan/tables/registry.rb', line 50

def tags
  @by_tag.keys
end