Module: Ucode::Aggregator

Defined in:
lib/ucode/aggregator.rb

Overview

Coverage analysis over codepoint sets.

Pure transformations: given a collection of codepoints and an ‘Index` (blocks or scripts), return aggregated summaries. No I/O, no mutation of inputs, no global state.

OCP: new aggregation kinds (planes, categories, …) slot in as new methods without altering existing ones.

Defined Under Namespace

Classes: BlockSummary

Class Method Summary collapse

Class Method Details

.aggregate_blocks(codepoints, blocks_index) ⇒ Array<BlockSummary>

Returns one summary per block in the index, in the index’s natural (first_cp) order.

Parameters:

  • codepoints (Enumerable<Integer>)
  • blocks_index (Ucode::Index)

Returns:

  • (Array<BlockSummary>)

    one summary per block in the index, in the index’s natural (first_cp) order



32
33
34
35
# File 'lib/ucode/aggregator.rb', line 32

def aggregate_blocks(codepoints, blocks_index)
  sorted = codepoints.sort
  blocks_index.map { |entry| build_block_summary(entry, sorted) }
end

.aggregate_scripts(codepoints, scripts_index) ⇒ Array<String>

Returns sorted unique script names covering the given codepoints.

Parameters:

  • codepoints (Enumerable<Integer>)
  • scripts_index (Ucode::Index)

Returns:

  • (Array<String>)

    sorted unique script names covering the given codepoints



41
42
43
# File 'lib/ucode/aggregator.rb', line 41

def aggregate_scripts(codepoints, scripts_index)
  codepoints.filter_map { |cp| scripts_index.lookup(cp) }.uniq.sort
end