Class: Ucode::Audit::UcdOnlyReference

Inherits:
CoverageReference show all
Defined in:
lib/ucode/audit/ucd_only_reference.rb

Overview

CoverageReference backed by a Database. The "legacy" reference: derives the assigned codepoint set from block ranges alone, with no per-codepoint provenance.

Used by the audit pipeline when no universal-set manifest is available (or the user explicitly opts out via --reference-universal-set=none). All audits before TODO 25 behaved this way.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(database:) ⇒ UcdOnlyReference

Returns a new instance of UcdOnlyReference.

Parameters:

  • database (Ucode::Database, nil)

    when nil, every query returns empty / false — caller should surface a warning.



16
17
18
19
# File 'lib/ucode/audit/ucd_only_reference.rb', line 16

def initialize(database:)
  super()
  @database = database
end

Instance Attribute Details

#databaseObject (readonly)

Returns the value of attribute database.



21
22
23
# File 'lib/ucode/audit/ucd_only_reference.rb', line 21

def database
  @database
end

Instance Method Details

#block_name_for(codepoint) ⇒ String?

Block name (verbatim Unicode identifier, e.g. "Basic_Latin") the codepoint falls under, or nil if it isn't in any known block. Used by BlockAggregator to group a font's cmap by block without needing direct access to the underlying Database.

Parameters:

  • codepoint (Integer)

Returns:

  • (String, nil)


36
37
38
39
40
# File 'lib/ucode/audit/ucd_only_reference.rb', line 36

def block_name_for(codepoint)
  return nil if @database.nil?

  @database.lookup_block(codepoint)
end

#entries_for_block(block_id) ⇒ Array<Entry>

Every assigned codepoint in the block, with tier + source attached when the reference carries provenance.

Parameters:

  • block_id (String)

    verbatim Unicode block name (e.g. "Basic_Latin", "Greek_and_Coptic")

Returns:

  • (Array<Entry>)

    sorted by codepoint; empty for unknown block names or blocks with no assigned codepoints



43
44
45
46
47
48
49
50
# File 'lib/ucode/audit/ucd_only_reference.rb', line 43

def entries_for_block(block_id)
  return [] if @database.nil?

  ranges = @database.block_ranges_by_name(block_id)
  return [] if ranges.nil? || ranges.empty?

  ranges.flat_map { |r| expand_range(r) }
end

#include?(codepoint) ⇒ Boolean

Returns true if the codepoint is in the reference set.

Parameters:

  • codepoint (Integer)

Returns:

  • (Boolean)

    true if the codepoint is in the reference set



29
30
31
32
33
# File 'lib/ucode/audit/ucd_only_reference.rb', line 29

def include?(codepoint)
  return false if @database.nil?

  !@database.lookup_block(codepoint).nil?
end

#kindSymbol

Returns :ucd.

Returns:

  • (Symbol)

    :ucd



24
25
26
# File 'lib/ucode/audit/ucd_only_reference.rb', line 24

def kind
  :ucd
end

#provenance_for(_codepoints) ⇒ nil

UCD-only references carry no provenance. Returning nil signals "do not populate missing_codepoint_provenance" so the audit report preserves the legacy wire shape.

Returns:

  • (nil)


63
64
65
# File 'lib/ucode/audit/ucd_only_reference.rb', line 63

def provenance_for(_codepoints)
  nil
end

#reference_idString

Stable identifier for the reference, embedded in audit reports so consumers can detect drift. Examples:

"ucd:17.0.0"
"universal-set:17.0.0:abc12345"

Returns:

  • (String)


53
54
55
56
# File 'lib/ucode/audit/ucd_only_reference.rb', line 53

def reference_id
  version = @database&.ucd_version || "unknown"
  "ucd:#{version}"
end