Module: Fontisan::Converters::ConversionStrategy
- Included in:
- OutlineConverter, SvgGenerator, TableCopier, Woff2Encoder, WoffWriter
- Defined in:
- lib/fontisan/converters/conversion_strategy.rb
Overview
Interface module for font format conversion strategies
[‘ConversionStrategy`](lib/fontisan/converters/conversion_strategy.rb) defines the contract that all conversion strategy classes must implement. This follows the Strategy pattern to enable polymorphic handling of different conversion types (TTF→OTF, OTF→TTF, same-format copying).
Each strategy must implement:
-
convert(font, options) - Perform the actual conversion
-
supported_conversions - Return array of [source, target] format pairs
-
validate(font, target_format) - Validate conversion is possible
Strategies are selected by [‘FormatConverter`](lib/fontisan/converters/format_converter.rb) based on source and target formats.
Instance Method Summary collapse
-
#convert(font, options = {}) ⇒ Hash<String, String>
Convert font to target format.
-
#supported_conversions ⇒ Array<Array<Symbol>>
Get list of supported conversions.
-
#supports?(source_format, target_format) ⇒ Boolean
Check if strategy supports a conversion.
-
#validate(font, target_format) ⇒ Boolean
Validate that conversion is possible.
Instance Method Details
#convert(font, options = {}) ⇒ Hash<String, String>
Convert font to target format
This method must return a hash of table tags to binary data, which will be assembled into a complete font by FontWriter.
49 50 51 52 |
# File 'lib/fontisan/converters/conversion_strategy.rb', line 49 def convert(font, = {}) raise NotImplementedError, "#{self.class.name} must implement convert(font, options)" end |
#supported_conversions ⇒ Array<Array<Symbol>>
Get list of supported conversions
Returns an array of [source_format, target_format] pairs that this strategy can handle.
65 66 67 68 |
# File 'lib/fontisan/converters/conversion_strategy.rb', line 65 def supported_conversions raise NotImplementedError, "#{self.class.name} must implement supported_conversions" end |
#supports?(source_format, target_format) ⇒ Boolean
Check if strategy supports a conversion
91 92 93 |
# File 'lib/fontisan/converters/conversion_strategy.rb', line 91 def supports?(source_format, target_format) supported_conversions.include?([source_format, target_format]) end |
#validate(font, target_format) ⇒ Boolean
Validate that conversion is possible
Checks if the given font can be converted to the target format. Should raise an error with a clear message if conversion is not possible.
81 82 83 84 |
# File 'lib/fontisan/converters/conversion_strategy.rb', line 81 def validate(font, target_format) raise NotImplementedError, "#{self.class.name} must implement validate(font, target_format)" end |