Class: Fontisan::Commands::LsCommand

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

Overview

Command to list contents of font files (collections or individual fonts).

This command provides a universal "ls" interface that auto-detects whether the input is a collection (TTC/OTC) or individual font (TTF/OTF) and returns the appropriate listing:

  • For collections: Lists all fonts in the collection
  • For individual fonts: Shows a quick summary

Examples:

List fonts in collection

command = LsCommand.new("fonts.ttc")
list = command.run
puts "Contains #{list.num_fonts} fonts"

Get font summary

command = LsCommand.new("font.ttf")
summary = command.run
puts "#{summary.family_name} - #{summary.num_glyphs} glyphs"

Instance Method Summary collapse

Constructor Details

#initialize(file_path, options = {}) ⇒ LsCommand

Initialize ls command

Parameters:

  • file_path (String)

    Path to font or collection file

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

    Command options

Options Hash (options):

  • :font_index (Integer)

    Index for TTC/OTC (unused for ls)



28
29
30
31
# File 'lib/fontisan/commands/ls_command.rb', line 28

def initialize(file_path, options = {})
  @file_path = file_path
  @options = options
end

Instance Method Details

#runCollectionListInfo, FontSummary

Execute the ls command

Auto-detects file type and returns appropriate model:

  • CollectionListInfo for TTC/OTC files
  • FontSummary for TTF/OTF files

Returns:

  • (CollectionListInfo, FontSummary)

    List or summary

Raises:

  • (Errno::ENOENT)

    if file does not exist

  • (Error)

    for loading or processing failures



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/fontisan/commands/ls_command.rb', line 42

def run
  if FontLoader.collection?(@file_path)
    list_collection
  else
    font_summary
  end
rescue Errno::ENOENT
  raise
rescue StandardError => e
  raise Error, "Failed to list file contents: #{e.message}"
end