Class: UkrainianLatin::Uklatn_uk_uk_Latn_DSTU_9112_B

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

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initializeUklatn_uk_uk_Latn_DSTU_9112_B

Returns a new instance of Uklatn_uk_uk_Latn_DSTU_9112_B.



57
58
59
60
61
62
63
64
# File 'lib/uklatn.rb', line 57

def initialize()
    @rx1 = /([Ьь](?=[АаЕеІіУу])|(?<=[Б-ДЖЗК-НП-ТФ-Щб-джзк-нп-тф-щҐґ])[Йй])|([ГЄЖЇХЩШЧЮЯЁЎЪЫЭ](?=\u0301?[а-яёєіїўґ’])|\b[Ьь])|([ЁЄІЇЎА-яёєіїўҐґ’])/
    @maps1 = [
        {"Ь"=>"J'","ь"=>"j'","Й"=>"'J","й"=>"'j"},
        {"Г"=>"Gh","Є"=>"Je","Ж"=>"Zh","Ї"=>"Ji","Х"=>"Kh","Щ"=>"Shch","Ш"=>"Sh","Ч"=>"Ch","Ю"=>"Ju","Я"=>"Ja","Ё"=>"Jow","Ў"=>"Uh","Ъ"=>"Oh","Ы"=>"Yw","Э"=>"Ehw","Ь"=>"Hj","ь"=>"hj"},
        {"А"=>"A","а"=>"a","Б"=>"B","б"=>"b","В"=>"V","в"=>"v","Г"=>"GH","г"=>"gh","Ґ"=>"G","ґ"=>"g","Д"=>"D","д"=>"d","Е"=>"E","е"=>"e","Є"=>"JE","є"=>"je","Ж"=>"ZH","ж"=>"zh","З"=>"Z","з"=>"z","И"=>"Y","и"=>"y","І"=>"I","і"=>"i","Ї"=>"JI","ї"=>"ji","Х"=>"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","Ц"=>"C","ц"=>"c","Ю"=>"JU","ю"=>"ju","Я"=>"JA","я"=>"ja","Й"=>"J","й"=>"j","Ь"=>"J","ь"=>"j",""=>"'","Ё"=>"JOW","ё"=>"jow","Ў"=>"UH","ў"=>"uh","Ъ"=>"OH","ъ"=>"oh","Ы"=>"YW","ы"=>"yw","Э"=>"EHW","э"=>"ehw"},
    ]
end

Instance Method Details

#transform(text) ⇒ Object



66
67
68
69
70
71
72
73
74
75
# File 'lib/uklatn.rb', line 66

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