Class: Ucode::CodeChart::BlockIndex
- Inherits:
-
Object
- Object
- Ucode::CodeChart::BlockIndex
- Defined in:
- lib/ucode/code_chart/block_index.rb
Overview
Owns assigned-codepoint membership for one Unicode block.
The single place in the CodeChart namespace that knows "what
codepoints belong to this block". Extractor, GapAnalyzer,
BatchRunner, and the CLI's list --coverage-gap-only all
consume this API — none of them re-derive block membership.
Definition of "assigned"
Two iteration modes, both supported:
* `#each_codepoint_in_range` — every Integer in
`block.range_first..block.range_last`. Fast, no I/O.
* `#each_assigned_codepoint` — same enumeration today; this
is the place to swap in a precise UCD-backed filter (walk
`UnicodeData.txt` for the block range) without changing
callers. The approximation matches the audit pipeline's
existing definition ({Ucode::Audit::UcdOnlyReference}).
OCP
Adding a new mode (e.g. :reserved_only, :noncharacter_only)
one new method. Adding a new precision level = override of
#each_assigned_codepoint. Callers never change.
Instance Attribute Summary collapse
- #block ⇒ Ucode::Models::Block readonly
Instance Method Summary collapse
- #assigned?(codepoint) ⇒ Boolean
-
#assigned_codepoints ⇒ Array<Integer>
Materialized view of #each_assigned_codepoint, sorted ascending.
-
#assigned_set ⇒ Set<Integer>
Frozen membership set; built once.
-
#each_assigned_codepoint {|codepoint| ... } ⇒ Enumerator, void
Yields assigned codepoints only.
-
#each_codepoint_in_range {|codepoint| ... } ⇒ Enumerator, void
Yields every codepoint in the block's range, ascending.
-
#initialize(block:) ⇒ BlockIndex
constructor
A new instance of BlockIndex.
-
#size ⇒ Integer
Count of assigned codepoints.
Constructor Details
#initialize(block:) ⇒ BlockIndex
Returns a new instance of BlockIndex.
31 32 33 |
# File 'lib/ucode/code_chart/block_index.rb', line 31 def initialize(block:) @block = block end |
Instance Attribute Details
#block ⇒ Ucode::Models::Block (readonly)
36 37 38 |
# File 'lib/ucode/code_chart/block_index.rb', line 36 def block @block end |
Instance Method Details
#assigned?(codepoint) ⇒ Boolean
79 80 81 |
# File 'lib/ucode/code_chart/block_index.rb', line 79 def assigned?(codepoint) assigned_set.include?(codepoint) end |
#assigned_codepoints ⇒ Array<Integer>
Returns materialized view of #each_assigned_codepoint, sorted ascending.
68 69 70 |
# File 'lib/ucode/code_chart/block_index.rb', line 68 def assigned_codepoints each_assigned_codepoint.to_a end |
#assigned_set ⇒ Set<Integer>
Returns frozen membership set; built once.
73 74 75 |
# File 'lib/ucode/code_chart/block_index.rb', line 73 def assigned_set @assigned_set ||= assigned_codepoints.to_set.freeze end |
#each_assigned_codepoint {|codepoint| ... } ⇒ Enumerator, void
Yields assigned codepoints only. Today this is equivalent to #each_codepoint_in_range — the audit pipeline's existing definition of "assigned" is range-based. A future enhancement can swap in a UCD-backed precise filter without changing any caller.
60 61 62 63 64 |
# File 'lib/ucode/code_chart/block_index.rb', line 60 def each_assigned_codepoint(&) return enum_for(:each_assigned_codepoint) unless block_given? each_codepoint_in_range(&) end |
#each_codepoint_in_range {|codepoint| ... } ⇒ Enumerator, void
Yields every codepoint in the block's range, ascending. Includes reserved/unassigned slots — callers that need only assigned codepoints should use #each_assigned_codepoint (or filter the result through whatever resolver they compose).
46 47 48 49 50 |
# File 'lib/ucode/code_chart/block_index.rb', line 46 def each_codepoint_in_range(&) return enum_for(:each_codepoint_in_range) unless block_given? (@block.range_first..@block.range_last).each(&) end |
#size ⇒ Integer
Returns count of assigned codepoints.
84 85 86 |
# File 'lib/ucode/code_chart/block_index.rb', line 84 def size assigned_codepoints.size end |