Class: Ucode::Repo::AggregateWriter
- Inherits:
-
Object
- Object
- Ucode::Repo::AggregateWriter
- Includes:
- AtomicWrites
- Defined in:
- lib/ucode/repo/aggregate_writer.rb
Overview
Writes every aggregate JSON file under ‘output/`:
output/planes/<n>.json
output/blocks/<ID>.json
output/blocks/index.json (block index)
output/scripts/<code>.json
output/index/names.json (cp_id → name)
output/index/labels.json (cp_id → {name, gc, sc})
output/index/codepoint_to_block.json (cp_id → block_id)
output/relationships/*.json (per-property tables)
output/enums.json (property aliases + value aliases)
output/named_sequences/<slug>.json
output/manifest.json
**Single pass**: callers feed one CodePoint at a time via ‘#add`; `#flush` writes all derived files using the Coordinator’s indices for the static tables (relationships, enums, named sequences).
MECE:
- paths: `Repo::Paths`
- atomic writes: `Repo::AtomicWrites`
- stream aggregation: this class
- serialization: lutaml-model `to_yaml_hash` / `to_json`
Instance Attribute Summary collapse
-
#codepoint_count ⇒ Object
readonly
Returns the value of attribute codepoint_count.
Instance Method Summary collapse
-
#add(cp) ⇒ void
Fold one CodePoint into the stream accumulators.
-
#flush(ucd_version:, indices:, property_aliases: [], property_value_aliases: [], named_sequences: [], glyph_count: 0) ⇒ Integer
Write every aggregate file.
-
#initialize(output_root) ⇒ AggregateWriter
constructor
A new instance of AggregateWriter.
Methods included from AtomicWrites
#same_content?, #to_pretty_json, #write_atomic
Constructor Details
#initialize(output_root) ⇒ AggregateWriter
Returns a new instance of AggregateWriter.
79 80 81 82 83 84 85 86 87 |
# File 'lib/ucode/repo/aggregate_writer.rb', line 79 def initialize(output_root) @output_root = Pathname.new(output_root) @block_codepoint_ids = Hash.new { |h, k| h[k] = [] } @script_codepoint_ids = Hash.new { |h, k| h[k] = [] } @names_index = {} @labels_index = {} @cp_to_block = {} @codepoint_count = 0 end |
Instance Attribute Details
#codepoint_count ⇒ Object (readonly)
Returns the value of attribute codepoint_count.
76 77 78 |
# File 'lib/ucode/repo/aggregate_writer.rb', line 76 def codepoint_count @codepoint_count end |
Instance Method Details
#add(cp) ⇒ void
This method returns an undefined value.
Fold one CodePoint into the stream accumulators. No-ops if the cp has no block_id (it has no home in the output tree).
93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/ucode/repo/aggregate_writer.rb', line 93 def add(cp) return if cp.block_id.nil? @block_codepoint_ids[cp.block_id] << cp.id if cp.script_code @script_codepoint_ids[cp.script_code] << cp.id end if cp.name && !cp.name.empty? @names_index[cp.id] = cp.name end @labels_index[cp.id] = build_label(cp) @cp_to_block[cp.id] = cp.block_id @codepoint_count += 1 end |
#flush(ucd_version:, indices:, property_aliases: [], property_value_aliases: [], named_sequences: [], glyph_count: 0) ⇒ Integer
Write every aggregate file. Optional params supply data that is not in ‘Coordinator::Indices` (the Coordinator only resolves the `sc` subset of PropertyValueAliases; the full alias tables and the named sequences are passed through from the CLI/parsers).
120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/ucode/repo/aggregate_writer.rb', line 120 def flush(ucd_version:, indices:, property_aliases: [], property_value_aliases: [], named_sequences: [], glyph_count: 0) writes = 0 writes += write_planes(indices.blocks) writes += write_blocks(indices.blocks) writes += write_scripts(indices.scripts) writes += write_indexes writes += write_relationships(indices) writes += write_enums(property_aliases, property_value_aliases) writes += write_named_sequences(named_sequences) writes += write_manifest(ucd_version: ucd_version, glyph_count: glyph_count) writes end |