Class: Ucode::Audit::Emitter::IndexEmitter

Inherits:
Object
  • Object
show all
Includes:
Repo::AtomicWrites
Defined in:
lib/ucode/audit/emitter/index_emitter.rb

Overview

Writes <face_dir>/index.json — the compact face overview the browser fetches first.

Compactness rules (per 03-directory-output-spec.md):

- `codepoint_details` never appears in `index.json`. The verbose
per-block detail is emitted by {CodepointEmitter}.
- `covered_codepoints` is dropped from each block entry. The
browser fetches `codepoints/<NAME>.json` for that.
- `missing_codepoints` is kept per block — it's the actionable
gap list and small in practice.
- Adds a derived `totals` block so a renderer doesn't have to
re-aggregate to draw the headline numbers.

Idempotent via Repo::AtomicWrites.

Instance Method Summary collapse

Methods included from Repo::AtomicWrites

#same_content?, #to_pretty_json, #write_atomic

Instance Method Details

#build_index(report, universal_set_root: nil, face_dir: nil) ⇒ Hash

Build the index.json shape (a Hash) for a report. Exposed so the HTML browser (Browser::FacePage) can reuse the exact same shape when inlining overview data into its template.

Parameters:

  • report (Models::Audit::AuditReport)
  • universal_set_root (String, Pathname, nil) (defaults to: nil)
  • face_dir (String, Pathname, nil) (defaults to: nil)

    required when universal_set_root is supplied (relative path resolution).

Returns:

  • (Hash)


52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/ucode/audit/emitter/index_emitter.rb', line 52

def build_index(report, universal_set_root: nil, face_dir: nil)
  {
    "generated_at" => report.generated_at,
    "ucode_version" => report.ucode_version,
    "font" => font_section(report),
    "baseline" => report.baseline&.to_hash,
    "totals" => build_totals(report),
    "discrepancies" => report.discrepancies.map(&:to_hash),
    "plane_summaries" => report.plane_summaries.map(&:to_hash),
    "block_summaries" => block_summaries(report),
    "script_summaries" => report.scripts.map(&:to_hash),
    "universal_set" => universal_set_section(universal_set_root, face_dir),
  }.compact
end

#emit(face_dir, report, universal_set_root: nil) ⇒ Boolean

Returns true if the file was written, false if skipped.

Parameters:

  • face_dir (String, Pathname)
  • report (Models::Audit::AuditReport)
  • universal_set_root (String, Pathname, nil) (defaults to: nil)

    when both this and face_dir are present and the root exists on disk, the index embeds a universal_set section with relative paths to the manifest + glyphs dir. nil otherwise.

Returns:

  • (Boolean)

    true if the file was written, false if skipped



37
38
39
40
41
# File 'lib/ucode/audit/emitter/index_emitter.rb', line 37

def emit(face_dir, report, universal_set_root: nil)
  payload = to_pretty_json(build_index(report, universal_set_root: universal_set_root,
                                               face_dir: face_dir))
  write_atomic(Paths.index_under(face_dir), payload)
end