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
-
.__clear__ ⇒ Object
Clear all registrations (testing only).
-
.for(tag) ⇒ Class?
Look up the table class for a tag.
- .register(tag, klass) ⇒ Object
-
.tag_for(klass) ⇒ String?
Reverse lookup: tag for a given class.
-
.tags ⇒ Array<String>
All registered tags.
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.
37 38 39 |
# File 'lib/fontisan/tables/registry.rb', line 37 def for(tag) @by_tag[tag] end |
.register(tag, klass) ⇒ Object
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.
45 46 47 |
# File 'lib/fontisan/tables/registry.rb', line 45 def tag_for(klass) @by_class[klass] end |
.tags ⇒ Array<String>
Returns All registered tags.
50 51 52 |
# File 'lib/fontisan/tables/registry.rb', line 50 def @by_tag.keys end |