Module: Vectory::Conversion
- Defined in:
- lib/vectory/conversion.rb,
lib/vectory/conversion/strategy.rb,
lib/vectory/conversion/inkscape_strategy.rb,
lib/vectory/conversion/ghostscript_strategy.rb
Overview
Conversion module provides strategy-based conversion interface
This module encapsulates different conversion strategies for converting between vector formats using external tools like Inkscape and Ghostscript.
Defined Under Namespace
Classes: GhostscriptStrategy, InkscapeStrategy, Strategy
Class Method Summary collapse
-
.convert(content, from:, to:, **options) ⇒ Vectory::Vector, String
Convert content from one format to another.
-
.strategies ⇒ Array<Vectory::Conversion::Strategy>
Get all available strategies.
-
.strategies_for(input_format, output_format) ⇒ Array<Vectory::Conversion::Strategy>
Get strategies that support a specific conversion.
-
.supported_conversions ⇒ Array<Array<Symbol>>
Get all supported conversions.
-
.supports?(input_format, output_format) ⇒ Boolean
Check if a conversion is supported.
-
.tool_available?(tool) ⇒ Boolean
Check if a specific tool is available.
Class Method Details
.convert(content, from:, to:, **options) ⇒ Vectory::Vector, String
Convert content from one format to another
Automatically selects the appropriate strategy based on the input/output formats.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/vectory/conversion.rb', line 30 def convert(content, from:, to:, **) strategy = find_strategy(from, to) unless strategy supported = supported_conversions.map do |a, b| "#{a} → #{b}" end.join(", ") raise Vectory::ConversionError, "No strategy found for #{from} → #{to} conversion. " \ "Supported: #{supported}" end strategy.convert(content, input_format: from, output_format: to, **) end |
.strategies ⇒ Array<Vectory::Conversion::Strategy>
Get all available strategies
49 50 51 52 53 54 |
# File 'lib/vectory/conversion.rb', line 49 def strategies @strategies ||= [ InkscapeStrategy.new, GhostscriptStrategy.new, ] end |
.strategies_for(input_format, output_format) ⇒ Array<Vectory::Conversion::Strategy>
Get strategies that support a specific conversion
61 62 63 |
# File 'lib/vectory/conversion.rb', line 61 def strategies_for(input_format, output_format) strategies.select { |s| s.supports?(input_format, output_format) } end |
.supported_conversions ⇒ Array<Array<Symbol>>
Get all supported conversions
77 78 79 |
# File 'lib/vectory/conversion.rb', line 77 def supported_conversions @supported_conversions ||= strategies.flat_map(&:supported_conversions).uniq end |
.supports?(input_format, output_format) ⇒ Boolean
Check if a conversion is supported
70 71 72 |
# File 'lib/vectory/conversion.rb', line 70 def supports?(input_format, output_format) strategies_for(input_format, output_format).any? end |
.tool_available?(tool) ⇒ Boolean
Check if a specific tool is available
85 86 87 88 |
# File 'lib/vectory/conversion.rb', line 85 def tool_available?(tool) strategy = strategies.find { |s| s.tool_name == tool.to_s.downcase } strategy&.available? || false end |