Module: Fontisan::Ucd::IndexBuilder

Defined in:
lib/fontisan/ucd/index_builder.rb

Overview

Turns a parsed Models::Ucd::Ucd instance into two compact run-length-encoded indices (blocks + scripts), and persists them to the cache for future Index loads.

Index layout on disk (YAML):

<root>/<version>/index/
blocks.yml
scripts.yml

Each file is an array of { first_cp:, last_cp:, name: } hashes, sorted by first_cp, disjoint.

Class Method Summary collapse

Class Method Details

.build(version) ⇒ Array(Index, Index)

Build + persist both indices for a cached version.

Parameters:

  • version (String)

Returns:

  • (Array(Index, Index))

    blocks_index, scripts_index



22
23
24
25
26
27
28
29
# File 'lib/fontisan/ucd/index_builder.rb', line 22

def build(version)
  ucd = load_ucd(version)
  blocks, scripts = build_from_ucd(ucd)
  CacheManager.index_dir(version).mkpath
  blocks.save(CacheManager.blocks_index_path(version))
  scripts.save(CacheManager.scripts_index_path(version))
  [blocks, scripts]
end

.build_from_ucd(ucd) ⇒ Array(Index, Index)

Pure: build both indices from an in-memory Ucd model.

Parameters:

Returns:



34
35
36
37
38
# File 'lib/fontisan/ucd/index_builder.rb', line 34

def build_from_ucd(ucd)
  blocks_runs = collect_runs(ucd, :block)
  scripts_runs = collect_runs(ucd, :script)
  [Index.new(to_entries(blocks_runs)), Index.new(to_entries(scripts_runs))]
end