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)



34
35
36
37
# File 'lib/fontisan/commands/ls_command.rb', line 34

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



48
49
50
51
52
53
54
55
56
57
58
# File 'lib/fontisan/commands/ls_command.rb', line 48

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