Class: Ucode::Audit::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/ucode/audit/context.rb

Overview

Value object carrying everything an extractor needs to do its job.

Extractors never reach back into AuditCommand state — they read exclusively from the Context. Shared derived data (codepoints, UCD baseline, source format) is memoized here so multiple extractors don’t recompute it.

ucode deltas vs fontisan’s Context:

  • Drops ‘cldr` and the entire CLDR resolution path (out of scope).

  • Replaces fontisan’s ‘ucd` memoizer with `baseline`, a struct carrying version + database + metadata.

  • Adds optional ‘renderer` for `–with-glyphs` mode (nil otherwise).

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(font:, font_path:, font_index:, num_fonts_in_source:, options:, renderer: nil) ⇒ Context

Returns a new instance of Context.

Parameters:

  • font (Fontisan::Font)

    parsed font handle (has_table?, table).

  • font_path (Pathname, String)

    source path for format detection.

  • font_index (Integer)

    0-based face index within a collection.

  • num_fonts_in_source (Integer)

    total faces in the source file.

  • options (Hash{Symbol=>Object})

    audit options (ucd_version, all_codepoints, with_glyphs, etc.).

  • renderer (Object, nil) (defaults to: nil)

    glyph renderer for –with-glyphs mode.



42
43
44
45
46
47
48
49
50
# File 'lib/ucode/audit/context.rb', line 42

def initialize(font:, font_path:, font_index:, num_fonts_in_source:,
               options:, renderer: nil)
  @font = font
  @font_path = font_path
  @font_index = font_index
  @num_fonts_in_source = num_fonts_in_source
  @options = options
  @renderer = renderer
end

Instance Attribute Details

#fontObject (readonly)

Returns the value of attribute font.



32
33
34
# File 'lib/ucode/audit/context.rb', line 32

def font
  @font
end

#font_indexObject (readonly)

Returns the value of attribute font_index.



32
33
34
# File 'lib/ucode/audit/context.rb', line 32

def font_index
  @font_index
end

#font_pathObject (readonly)

Returns the value of attribute font_path.



32
33
34
# File 'lib/ucode/audit/context.rb', line 32

def font_path
  @font_path
end

#num_fonts_in_sourceObject (readonly)

Returns the value of attribute num_fonts_in_source.



32
33
34
# File 'lib/ucode/audit/context.rb', line 32

def num_fonts_in_source
  @num_fonts_in_source
end

#optionsObject (readonly)

Returns the value of attribute options.



32
33
34
# File 'lib/ucode/audit/context.rb', line 32

def options
  @options
end

#rendererObject (readonly)

Returns the value of attribute renderer.



32
33
34
# File 'lib/ucode/audit/context.rb', line 32

def renderer
  @renderer
end

Instance Method Details

#all_codepoints?Boolean

True when the user asked for every codepoint (including unassigned) in the report’s ‘codepoints` field.

Returns:

  • (Boolean)


75
76
77
# File 'lib/ucode/audit/context.rb', line 75

def all_codepoints?
  @options[:all_codepoints] == true
end

#baselineBaseline

Pre-resolved baseline (UCD version + database + metadata). Memoized. When resolution fails, returns a Baseline with a ‘warning` and nil database so extractors can degrade gracefully.

Returns:

  • (Baseline)


62
63
64
# File 'lib/ucode/audit/context.rb', line 62

def baseline
  @baseline ||= resolve_baseline
end

#codepointsArray<Integer>

Codepoints the font’s cmap actually maps. Memoized.

Returns:

  • (Array<Integer>)


54
55
56
# File 'lib/ucode/audit/context.rb', line 54

def codepoints
  @codepoints ||= extract_codepoints
end

#source_formatString?

Detected source format string (“ttf”, “otf”, “ttc”, …). Memoized.

Returns:

  • (String, nil)


68
69
70
# File 'lib/ucode/audit/context.rb', line 68

def source_format
  @source_format ||= Fontisan::FontLoader.detect_format(@font_path)&.to_s
end

#with_glyphs?Boolean

True when glyph rendering is requested (–with-glyphs).

Returns:

  • (Boolean)


81
82
83
# File 'lib/ucode/audit/context.rb', line 81

def with_glyphs?
  @options[:with_glyphs] == true && !@renderer.nil?
end