Class: Ucode::Parsers::PropertyValueAliases

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

Overview

Parses ‘PropertyValueAliases.txt` — per-property value aliases.

Format (UAX #44):

property; short_value; long_value; other_alias; ...

Examples:

gc; Lu; Uppercase_Letter
sc; Latn; Latin
ccc; 0; NR

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 PropertyValueAlias per non-comment line. Returns a lazy Enumerator when called without a block.



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

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

    property = fields[0]
    short = fields[1]
    long = fields[2]
    others = fields[3..].reject { |f| f.nil? || f.empty? }

    yield Models::PropertyValueAlias.new(
      property: property,
      short: short,
      long: long,
      other_aliases: others
    )
  end

  nil
end