Class: Ucode::Glyphs::Resolver
- Inherits:
-
Object
- Object
- Ucode::Glyphs::Resolver
- 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
-
#initialize(sources:, order: DEFAULT_ORDER) ⇒ Resolver
constructor
A new instance of Resolver.
-
#resolve(codepoint) ⇒ Source::Result?
Nil only when every source in every configured tier returned nil.
-
#sources ⇒ Array<Source>
Every source the resolver holds, flat.
-
#sources_for_tier(tier) ⇒ Array<Source>
Sources registered for the given tier.
Constructor Details
#initialize(sources:, order: DEFAULT_ORDER) ⇒ Resolver
Returns a new instance of Resolver.
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.
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 |
#sources ⇒ Array<Source>
Returns 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.
57 58 59 |
# File 'lib/ucode/glyphs/resolver.rb', line 57 def sources_for_tier(tier) Array(@sources_by_tier[tier]) end |