Class: UkrainianLatin::Uklatn_uk_uk_Latn_KMU_55

Inherits:
Object
  • Object
show all
Defined in:
lib/uklatn.rb

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initializeUklatn_uk_uk_Latn_KMU_55

Returns a new instance of Uklatn_uk_uk_Latn_KMU_55.



79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/uklatn.rb', line 79

def initialize()
    @rx1 = /(?<=[ЁЄІЇЎА-яёєіїўҐґ])([’\u0027])(?=[ЁЄІЇЎА-яёєіїўҐґ])/
    @maps1 = [
        {""=>"","'"=>""},
    ]
    @rx2 = /\b([ЄЇЮЯ])(?=\u0301?[а-яёєіїўґ’])|\b([ЙйЄЇЮЯєїюя])|([Зз]Г|[ЖХЦЩШЧЄЇЮЯ])(?=\u0301?[а-яёєіїўґ’])|([Зз][Гг]|[ЄІЇА-ЩЬЮ-щьюяєіїҐґ’])/
    @maps2 = [
        {"Є"=>"Ye","Ї"=>"Yi","Ю"=>"Yu","Я"=>"Ya"},
        {"Й"=>"Y","й"=>"y","Є"=>"YE","є"=>"ye","Ї"=>"YI","ї"=>"yi","Ю"=>"YU","ю"=>"yu","Я"=>"YA","я"=>"ya"},
        {"ЗГ"=>"ZGh","зГ"=>"zGh","Ж"=>"Zh","Х"=>"Kh","Ц"=>"Ts","Щ"=>"Shch","Ш"=>"Sh","Ч"=>"Ch","Є"=>"Ie","Ї"=>"I","Ю"=>"Iu","Я"=>"Ia"},
        {"ЗГ"=>"ZGH","Зг"=>"Zgh","зГ"=>"zGH","зг"=>"zgh","А"=>"A","а"=>"a","Б"=>"B","б"=>"b","В"=>"V","в"=>"v","Г"=>"H","г"=>"h","Ґ"=>"G","ґ"=>"g","Д"=>"D","д"=>"d","Е"=>"E","е"=>"e","Є"=>"IE","є"=>"ie","Ж"=>"ZH","ж"=>"zh","З"=>"Z","з"=>"z","И"=>"Y","и"=>"y","І"=>"I","і"=>"i","Ї"=>"I","ї"=>"i","Х"=>"KH","х"=>"kh","К"=>"K","к"=>"k","Л"=>"L","л"=>"l","М"=>"M","м"=>"m","Н"=>"N","н"=>"n","О"=>"O","о"=>"o","П"=>"P","п"=>"p","Р"=>"R","р"=>"r","Щ"=>"SHCH","щ"=>"shch","Ш"=>"SH","ш"=>"sh","С"=>"S","с"=>"s","Т"=>"T","т"=>"t","У"=>"U","у"=>"u","Ф"=>"F","ф"=>"f","Ч"=>"CH","ч"=>"ch","Ц"=>"TS","ц"=>"ts","Ю"=>"IU","ю"=>"iu","Я"=>"IA","я"=>"ia","Й"=>"I","й"=>"i","Ь"=>"","ь"=>"",""=>""},
    ]
end

Instance Method Details

#transform(text) ⇒ Object



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/uklatn.rb', line 93

def transform(text)
    text = text.unicode_normalize(:nfc)
    text = text.gsub(@rx1) do |m|
        next @maps1[0].fetch($1, $1) unless $1.nil?
        m
    end
    text = text.gsub(@rx2) do |m|
        next @maps2[3].fetch($4, $4) unless $4.nil?
        next @maps2[2].fetch($3, $3) unless $3.nil?
        next @maps2[1].fetch($2, $2) unless $2.nil?
        next @maps2[0].fetch($1, $1) unless $1.nil?
        m
    end
    text = text.unicode_normalize(:nfc)
end