Class: Fontisan::Commands::BaseCommand

Inherits:
Object
  • Object
show all
Defined in:
lib/fontisan/commands/base_command.rb

Overview

Abstract base class for all CLI commands.

Provides common functionality for loading fonts using FontLoader for automatic format detection. Works polymorphically with TrueTypeFont and OpenTypeFont instances.

Subclasses must implement the ‘run` method to define command-specific behavior.

Examples:

Creating a command subclass

class MyCommand < BaseCommand
  def run
    info = Models::FontInfo.new
    info.family_name = font.table("name").english_name(Tables::Name::FAMILY)
    info
  end
end

Instance Method Summary collapse

Constructor Details

#initialize(font_path, options = {}) ⇒ BaseCommand

Initialize a new command with a font file path and options.

Parameters:

  • font_path (String)

    Path to the font file

  • options (Hash) (defaults to: {})

    Optional command options

Options Hash (options):

  • :font_index (Integer)

    Index of font in TTC/OTC collection (default: 0)



30
31
32
33
34
# File 'lib/fontisan/commands/base_command.rb', line 30

def initialize(font_path, options = {})
  @font_path = font_path
  @options = options
  @font = load_font
end

Instance Method Details

#runModels::*

Execute the command.

This method must be implemented by subclasses.

Returns:

  • (Models::*)

    Command-specific result as lutaml-model object

Raises:

  • (NotImplementedError)

    if not implemented by subclass



42
43
44
# File 'lib/fontisan/commands/base_command.rb', line 42

def run
  raise NotImplementedError, "Subclasses must implement the run method"
end