Class: Fontisan::Stitcher::FormatMetadata
- Inherits:
-
Object
- Object
- Fontisan::Stitcher::FormatMetadata
- Defined in:
- lib/fontisan/stitcher/format_metadata.rb
Overview
Immutable metadata about a stitcher output format. Single source
of truth for "given a format symbol, what compiler / collection
format / file extension does it use?". Adding a new format =
adding a when branch in FormatMetadata.resolve; no other site in Stitcher
needs to know the mapping.
Instance Attribute Summary collapse
-
#collection_format ⇒ Object
readonly
Returns the value of attribute collection_format.
-
#compiler_class ⇒ Object
readonly
Returns the value of attribute compiler_class.
-
#extension ⇒ Object
readonly
Returns the value of attribute extension.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
-
.resolve(name) ⇒ FormatMetadata
Resolve a format name (Symbol or String) to its metadata.
Instance Method Summary collapse
-
#initialize(name:, compiler_class:, collection_format:, extension:) ⇒ FormatMetadata
constructor
A new instance of FormatMetadata.
Constructor Details
#initialize(name:, compiler_class:, collection_format:, extension:) ⇒ FormatMetadata
Returns a new instance of FormatMetadata.
20 21 22 23 24 25 |
# File 'lib/fontisan/stitcher/format_metadata.rb', line 20 def initialize(name:, compiler_class:, collection_format:, extension:) @name = name @compiler_class = compiler_class @collection_format = collection_format @extension = extension end |
Instance Attribute Details
#collection_format ⇒ Object (readonly)
Returns the value of attribute collection_format.
11 12 13 |
# File 'lib/fontisan/stitcher/format_metadata.rb', line 11 def collection_format @collection_format end |
#compiler_class ⇒ Object (readonly)
Returns the value of attribute compiler_class.
11 12 13 |
# File 'lib/fontisan/stitcher/format_metadata.rb', line 11 def compiler_class @compiler_class end |
#extension ⇒ Object (readonly)
Returns the value of attribute extension.
11 12 13 |
# File 'lib/fontisan/stitcher/format_metadata.rb', line 11 def extension @extension end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
11 12 13 |
# File 'lib/fontisan/stitcher/format_metadata.rb', line 11 def name @name end |
Class Method Details
.resolve(name) ⇒ FormatMetadata
Resolve a format name (Symbol or String) to its metadata.
Constants are referenced inside when branches so autoload
fires only for the requested format, not all of them.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/fontisan/stitcher/format_metadata.rb', line 34 def self.resolve(name) case name.to_sym when :ttf new(name: :ttf, compiler_class: Ufo::Compile::TtfCompiler, collection_format: :ttc, extension: ".ttf") when :otf new(name: :otf, compiler_class: Ufo::Compile::OtfCompiler, collection_format: :otc, extension: ".otf") when :otf2 new(name: :otf2, compiler_class: Ufo::Compile::Otf2Compiler, collection_format: :otc, extension: ".otf") else raise ArgumentError, "unknown format: #{name.inspect}" end end |