Class: Ucode::Parsers::NameAliases

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

Overview

Parses ‘NameAliases.txt` — alternate / correction / control names attached to a codepoint.

Format (UAX #44):

cp; alias_text; type

‘type` is one of: correction, control, alternate, figment, abbreviation.

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

Yields one NameAlias per non-comment line. Returns a lazy Enumerator when called without a block.



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/ucode/parsers/name_aliases.rb', line 20

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])
    text = fields[1]
    type = fields[2]
    next if text.nil? || text.empty? || type.nil? || type.empty?

    yield Models::NameAlias.new(
      codepoint: cp,
      text: text,
      type: type
    )
  end

  nil
end