Class: Ucode::Parsers::BidiBrackets

Inherits:
Base
  • Object
show all
Defined in:
lib/ucode/parsers/bidi_brackets.rb

Overview

Parses ‘BidiBrackets.txt` — paired bracket partners.

Format (UAX #44):

cp; paired_cp; type

‘type` is `o` (open) or `c` (close). Coordinator merges each row into `CodePoint#bidi.paired_bracket_id` and `.paired_bracket_type`.

Class Method Summary collapse

Methods inherited from Base

each_line, parse_codepoint_or_range, parse_field, parse_hex_cp

Class Method Details

.each_record(path) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/ucode/parsers/bidi_brackets.rb', line 17

def each_record(path)
  return enum_for(:each_record, path) unless block_given?

  each_line(path) do |line|
    fields = line.fields
    next if fields.length < 3

    cp = parse_hex_cp(fields[0])
    paired_cp = parse_hex_cp(fields[1])
    type = fields[2]
    next if type.nil? || type.empty?

    yield Models::BidiBracketPair.new(
      codepoint: cp,
      paired_id: format("U+%04X", paired_cp),
      type: type
    )
  end

  nil
end