Module: Ucode::Audit::CodepointRangeCoalescer
- Defined in:
- lib/ucode/audit/codepoint_range_coalescer.rb
Overview
Coalesces a flat codepoint list into contiguous Models::Audit::CodepointRange instances.
Pure function: input is any Enumerable<Integer>, output is a sorted array of contiguous ranges. Used by Extractors::Coverage to produce the compact range view that is the default AuditReport shape.
Class Method Summary collapse
-
.call(codepoints) ⇒ Array<Models::Audit::CodepointRange>
Contiguous, sorted.
Class Method Details
.call(codepoints) ⇒ Array<Models::Audit::CodepointRange>
Returns contiguous, sorted.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/ucode/audit/codepoint_range_coalescer.rb', line 16 def call(codepoints) return [] if codepoints.nil? || codepoints.empty? sorted = codepoints.sort.uniq ranges = [] range_start = sorted[0] prev = sorted[0] sorted[1..].each do |cp| next if cp == prev if cp == prev + 1 prev = cp else ranges << Models::Audit::CodepointRange.new(first_cp: range_start, last_cp: prev) range_start = cp prev = cp end end ranges << Models::Audit::CodepointRange.new(first_cp: range_start, last_cp: prev) ranges end |