Class: Ucode::Glyphs::Resolver

Inherits:
Object
  • Object
show all
Defined in:
lib/ucode/glyphs/resolver.rb

Overview

Priority-ordered glyph resolver — the heart of the 4-tier sourcing strategy.

Holds a flat array of Source instances (any tier, any number per tier) and tries them in order: until one returns a Source::Result. Tries are tier-major, source-minor: within a tier, sources are tried in the order they were passed to the constructor. This lets callers express "try FSung-1 before FSung-2 before Noto CJK JP" by simply ordering the Tier 1 sources that way.

The default order is Tier 1 → Pillar 1 → Pillar 2 → Pillar 3, but callers can override (e.g. tests may want [:pillar3] only).

The resolver is a pure orchestrator: it doesn't know about UCD blocks, fontist formulas, or PDF parsing. Those concerns live in the individual Source subclasses and in SourceBuilder.

Instance Method Summary collapse

Constructor Details

#initialize(sources:, order: DEFAULT_ORDER) ⇒ Resolver

Returns a new instance of Resolver.

Parameters:

  • sources (Array<Source>)

    flat list; grouped by tier internally. Sources with the same tier are tried in the order they appear here.

  • order (Array<Symbol>) (defaults to: DEFAULT_ORDER)

    tier resolution order. Default: %i[tier1 pillar1 pillar2 pillar3].



30
31
32
33
# File 'lib/ucode/glyphs/resolver.rb', line 30

def initialize(sources:, order: DEFAULT_ORDER)
  @sources_by_tier = sources.group_by(&:tier)
  @order = order
end

Instance Method Details

#resolve(codepoint) ⇒ Source::Result?

Returns nil only when every source in every configured tier returned nil. With a Pillar 3 source configured, this should be unreachable for assigned codepoints — Pillar 3 catches the tail.

Parameters:

  • codepoint (Integer)

Returns:

  • (Source::Result, nil)

    nil only when every source in every configured tier returned nil. With a Pillar 3 source configured, this should be unreachable for assigned codepoints — Pillar 3 catches the tail.



40
41
42
43
44
45
46
47
48
# File 'lib/ucode/glyphs/resolver.rb', line 40

def resolve(codepoint)
  @order.each do |tier|
    Array(@sources_by_tier[tier]).each do |source|
      result = source.fetch(codepoint)
      return result if result
    end
  end
  nil
end

#sourcesArray<Source>

Returns every source the resolver holds, flat.

Returns:

  • (Array<Source>)

    every source the resolver holds, flat.



51
52
53
# File 'lib/ucode/glyphs/resolver.rb', line 51

def sources
  @sources_by_tier.values.flatten
end

#sources_for_tier(tier) ⇒ Array<Source>

Returns sources registered for the given tier.

Parameters:

  • tier (Symbol)

Returns:

  • (Array<Source>)

    sources registered for the given tier



57
58
59
# File 'lib/ucode/glyphs/resolver.rb', line 57

def sources_for_tier(tier)
  Array(@sources_by_tier[tier])
end