Class: Ucode::Models::GlyphSourceMap

Inherits:
Lutaml::Model::Serializable
  • Object
show all
Defined in:
lib/ucode/models/glyph_source_map.rb

Overview

Top-level shape of config/unicode17_universal_glyph_set.yml. Pairs envelope metadata (Unicode + ucode version, generated_at) with the block→sources map itself.

Block keys are the verbatim Unicode block name with runs of whitespace collapsed to a single underscore — the canonical block id used everywhere else in this codebase (see Parsers::Blocks): "Basic_Latin", "Greek_and_Coptic", "CJK_Unified_Ideographs_Extension_J". Never slugified beyond whitespace collapsing.

Wire shape (note: map: is a hash keyed by block id, not an array):

unicode_version: "17.0.0"
ucode_version: "0.2.0"
generated_at: "2026-06-28T00:00:00Z"
default_sources:                 # applies when a block's sources are absent/empty
- kind: fontist
  label: noto-sans
  priority: 1
  license: OFL
map:
Basic_Latin:
  sources:
    - kind: fontist
      label: noto-sans
      priority: 1
Sidetic:
  sources: []

An entry with sources: [] (or omitted) is valid: it declares "no block-specific Tier 1 font; fall back to default_sources, then to Pillars 1-3". The fallback chain is implemented in #sources_for; the raw map is left untouched.

The hash is stored as a raw :hash attribute (lutaml-model collection semantics don't pair cleanly with a hash-keyed wire shape); the typed accessors wrap each entry's raw hashes in GlyphSource instances on demand.

Instance Method Summary collapse

Instance Method Details

#block_idsArray<String>

Returns every block_id that appears in the map (regardless of whether it has sources).

Returns:

  • (Array<String>)

    every block_id that appears in the map (regardless of whether it has sources).



93
94
95
# File 'lib/ucode/models/glyph_source_map.rb', line 93

def block_ids
  block_sources.keys
end

#configured_block_idsArray<String>

Returns block_ids whose own sources: list has at least one entry. Blocks relying on default_sources are excluded — they have no block-specific policy.

Returns:

  • (Array<String>)

    block_ids whose own sources: list has at least one entry. Blocks relying on default_sources are excluded — they have no block-specific policy.



100
101
102
103
104
# File 'lib/ucode/models/glyph_source_map.rb', line 100

def configured_block_ids
  block_sources.each_with_object([]) do |(block_id, raw), acc|
    acc << block_id if any_sources?(raw)
  end
end

#default_sourcesArray<GlyphSource>

Returns the top-level default sources, typed and priority-sorted. Empty when not declared.

Returns:

  • (Array<GlyphSource>)

    the top-level default sources, typed and priority-sorted. Empty when not declared.



78
79
80
81
82
# File 'lib/ucode/models/glyph_source_map.rb', line 78

def default_sources
  default_sources_list
    .map { |h| GlyphSource.from_hash(h.transform_keys(&:to_s)) }
    .sort_by(&:priority)
end

#has_block?(block_id) ⇒ Boolean

Returns true if the block has any entry in the map (even with empty sources). Does not consider default_sources.

Parameters:

  • block_id (String)

Returns:

  • (Boolean)

    true if the block has any entry in the map (even with empty sources). Does not consider default_sources.



87
88
89
# File 'lib/ucode/models/glyph_source_map.rb', line 87

def has_block?(block_id)
  block_sources.key?(block_id)
end

#sources_for(block_id) ⇒ Array<GlyphSource>

Returns sources for the block, in priority order (ascending). Falls through block-specific → default_sources → empty.

Parameters:

  • block_id (String)

    verbatim block id (underscore form)

Returns:

  • (Array<GlyphSource>)

    sources for the block, in priority order (ascending). Falls through block-specific → default_sources → empty.



68
69
70
71
72
73
74
# File 'lib/ucode/models/glyph_source_map.rb', line 68

def sources_for(block_id)
  raw = block_sources[block_id]
  list = extract_sources_list(raw)
  list = default_sources_list if list.empty?
  list.map { |h| GlyphSource.from_hash(h.transform_keys(&:to_s)) }
    .sort_by(&:priority)
end