Class: Ucode::Unicode::Catalog

Inherits:
Object
  • Object
show all
Defined in:
lib/ucode/unicode/catalog.rb

Overview

Version-specific query interface for Unicode metadata.

Deep module: small interface (10 public methods), large frozen dataset behind it (~346 blocks + 17 planes + counts). Constructed once per version; all lookups are O(1) or O(log N).

Thread-safe: all internal structures are frozen at construction. No mutation after initialize. No locks needed.

Construct via for_version — do not call new directly unless you have a pre-normalized version string.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(version:) ⇒ Catalog

Returns a new instance of Catalog.



19
20
21
22
23
24
# File 'lib/ucode/unicode/catalog.rb', line 19

def initialize(version:)
  @version = version
   = (version)
  build_indexes()
  freeze
end

Instance Attribute Details

#versionObject (readonly)

Returns the value of attribute version.



17
18
19
# File 'lib/ucode/unicode/catalog.rb', line 17

def version
  @version
end

Instance Method Details

#all_blocksObject



63
64
65
# File 'lib/ucode/unicode/catalog.rb', line 63

def all_blocks
  @all_blocks
end

#all_planesObject



67
68
69
# File 'lib/ucode/unicode/catalog.rb', line 67

def all_planes
  @all_planes
end

#assigned_countObject



26
27
28
# File 'lib/ucode/unicode/catalog.rb', line 26

def assigned_count
  @assigned_count
end

#assigned_in_plane(plane_number) ⇒ Object



30
31
32
# File 'lib/ucode/unicode/catalog.rb', line 30

def assigned_in_plane(plane_number)
  @assigned_by_plane[plane_number] || 0
end

#blocks_in_plane(plane_number) ⇒ Object



59
60
61
# File 'lib/ucode/unicode/catalog.rb', line 59

def blocks_in_plane(plane_number)
  @blocks_by_plane[plane_number] || EMPTY_BLOCKS
end

#find_block(block_id) ⇒ Object



42
43
44
# File 'lib/ucode/unicode/catalog.rb', line 42

def find_block(block_id)
  @blocks_by_id[block_id]
end

#find_block_by_codepoint(codepoint) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/ucode/unicode/catalog.rb', line 46

def find_block_by_codepoint(codepoint)
  idx = @block_ranges.bsearch_index do |(_first, last, _block)|
    if codepoint < _first
      -1
    elsif codepoint > last
      1
    else
      0
    end
  end
  idx.nil? ? nil : @block_ranges[idx][2]
end

#find_plane(plane_number) ⇒ Object



34
35
36
# File 'lib/ucode/unicode/catalog.rb', line 34

def find_plane(plane_number)
  @planes_by_number[plane_number]
end

#find_plane_by_codepoint(codepoint) ⇒ Object



38
39
40
# File 'lib/ucode/unicode/catalog.rb', line 38

def find_plane_by_codepoint(codepoint)
  find_plane(codepoint >> 16)
end