Class: Vectory::Conversion::Strategy Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/vectory/conversion/strategy.rb

Overview

This class is abstract.

Subclasses must implement the #convert method

Base class for conversion strategies

Conversion strategies encapsulate the logic for converting between different vector formats using external tools (Inkscape, Ghostscript, etc.)

Direct Known Subclasses

GhostscriptStrategy, InkscapeStrategy

Instance Method Summary collapse

Instance Method Details

#available?Boolean

Check if the required external tool is available

Returns:

  • (Boolean)

    true if the tool is available

Raises:



45
46
47
48
# File 'lib/vectory/conversion/strategy.rb', line 45

def available?
  raise NotImplementedError,
        "#{self.class} must implement #available? method"
end

#convert(content, input_format:, output_format:, **options) ⇒ String

This method is abstract.

Convert content from one format to another

Parameters:

  • content (String)

    the input content to convert

  • input_format (Symbol)

    the input format (e.g., :svg, :eps, :ps)

  • output_format (Symbol)

    the desired output format (e.g., :svg, :pdf, :eps)

  • options (Hash)

    additional options for the conversion

Returns:

  • (String)

    the converted content

Raises:



21
22
23
24
# File 'lib/vectory/conversion/strategy.rb', line 21

def convert(content, input_format:, output_format:, **options)
  raise NotImplementedError,
        "#{self.class} must implement #convert method"
end

#supported_conversionsArray<Array<Symbol>>

Get the list of conversions this strategy supports

Returns:

  • (Array<Array<Symbol>>)

    array of [input, output] format pairs



38
39
40
# File 'lib/vectory/conversion/strategy.rb', line 38

def supported_conversions
  []
end

#supports?(input_format, output_format) ⇒ Boolean

Check if this strategy supports the given conversion

Parameters:

  • input_format (Symbol)

    the input format

  • output_format (Symbol)

    the output format

Returns:

  • (Boolean)

    true if this strategy supports the conversion



31
32
33
# File 'lib/vectory/conversion/strategy.rb', line 31

def supports?(input_format, output_format)
  supported_conversions.include?([input_format, output_format])
end

#tool_nameString

Get the name of the external tool used by this strategy

Returns:

  • (String)

    the tool name



53
54
55
# File 'lib/vectory/conversion/strategy.rb', line 53

def tool_name
  self.class.name.split("::").last.gsub(/Strategy$/, "").downcase
end