Class: Fontisan::Commands::AuditCommand

Inherits:
BaseCommand show all
Defined in:
lib/fontisan/commands/audit_command.rb

Overview

Produces a complete per-face font audit report.

One AuditReport per face. For standalone fonts (TTF/OTF/WOFF/WOFF2), #run returns a single AuditReport. For collections (TTC/OTC/dfont), #run returns an Array — one per face, in source order.

The report is assembled by running every extractor in Audit::Registry against an Audit::Context. Each extractor owns one concern (provenance, identity, style, coverage, aggregations, …). Adding a new concern means adding one extractor class and one line in the registry — AuditCommand itself never changes.

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseCommand

#initialize

Constructor Details

This class inherits a constructor from Fontisan::Commands::BaseCommand

Class Method Details

.output_filename(report, format) ⇒ String

Compute the per-face filename for a report.

Parameters:

Returns:

  • (String)

    filename only (no directory)



52
53
54
55
56
57
58
59
60
61
62
# File 'lib/fontisan/commands/audit_command.rb', line 52

def self.output_filename(report, format)
  ext = format == :json ? "json" : "yaml"
  base = if report.num_fonts_in_source == 1
           safe_filename(report.postscript_name || report.family_name || "font")
         else
           format("%<idx>02d-%<name>s",
                  idx: report.font_index,
                  name: safe_filename(report.postscript_name || "face"))
         end
  "#{base}.#{ext}"
end

.safe_filename(name) ⇒ String

Sanitize an arbitrary string into a filesystem-safe basename.

Parameters:

  • name (String, nil)

Returns:

  • (String)


68
69
70
71
72
# File 'lib/fontisan/commands/audit_command.rb', line 68

def self.safe_filename(name)
  return "font" if name.nil? || name.empty?

  name.gsub(/[^A-Za-z0-9._-]/, "_")
end

.write_reports(reports, to:, format: :yaml) ⇒ Array<String>

Write one file per face under to (a directory). Pure utility — operates on a pre-built reports array, no font_path required.

Parameters:

  • reports (Array<Models::Audit::AuditReport>)
  • to (String)

    output directory; created if missing

  • format (Symbol) (defaults to: :yaml)

    :yaml or :json

Returns:

  • (Array<String>)

    written file paths



36
37
38
39
40
41
42
43
44
45
# File 'lib/fontisan/commands/audit_command.rb', line 36

def self.write_reports(reports, to:, format: :yaml)
  FileUtils.mkdir_p(to)

  reports.map do |report|
    path = File.join(to, output_filename(report, format))
    content = format == :json ? report.to_json : report.to_yaml
    File.write(path, content)
    path
  end
end

Instance Method Details

#runModels::Audit::AuditReport+



21
22
23
24
25
26
27
# File 'lib/fontisan/commands/audit_command.rb', line 21

def run
  if FontLoader.collection?(@font_path)
    audit_collection
  else
    audit_face(@font, 0, 1)
  end
end