Class: Ucode::CodeChart::GapAnalyzer::Analyzer

Inherits:
Object
  • Object
show all
Defined in:
lib/ucode/code_chart/gap_analyzer.rb

Overview

Composes a Manifest parser with the BlockIndex factory to produce BlockGaps.

Instance Method Summary collapse

Constructor Details

#initialize(manifest:, blocks:, block_index_class: BlockIndex) ⇒ Analyzer

Returns a new instance of Analyzer.

Parameters:

  • manifest (Manifest)

    parsed manifest

  • blocks (Hash{String=>Ucode::Models::Block})

    block_id → Block model lookup. Used to construct BlockIndex per gap block.

  • block_index_class (Class) (defaults to: BlockIndex)

    injectable BlockIndex class for tests



34
35
36
37
38
# File 'lib/ucode/code_chart/gap_analyzer.rb', line 34

def initialize(manifest:, blocks:, block_index_class: BlockIndex)
  @manifest = manifest
  @blocks = blocks
  @block_index_class = block_index_class
end

Instance Method Details

#block_gapsArray<BlockGap>

Returns one per block with at least one missing codepoint. Blocks with full coverage are excluded.

Returns:

  • (Array<BlockGap>)

    one per block with at least one missing codepoint. Blocks with full coverage are excluded.



53
54
55
# File 'lib/ucode/code_chart/gap_analyzer.rb', line 53

def block_gaps
  each_block_gap.to_a
end

#each_block_gap {|block_gap| ... } ⇒ Enumerator, void

Yield Parameters:

Returns:

  • (Enumerator, void)


42
43
44
45
46
47
48
49
# File 'lib/ucode/code_chart/gap_analyzer.rb', line 42

def each_block_gap
  return enum_for(:each_block_gap) unless block_given?

  @manifest.coverage_by_block.each_key do |block_id|
    gap = build_gap(block_id)
    yield gap unless gap.empty?
  end
end

#total_missing_codepointsInteger

Returns sum of missing codepoints across blocks.

Returns:

  • (Integer)

    sum of missing codepoints across blocks



58
59
60
# File 'lib/ucode/code_chart/gap_analyzer.rb', line 58

def total_missing_codepoints
  block_gaps.sum(&:size)
end