forked from aspotashev/rus-usa-tr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrans.rb
executable file
·60 lines (53 loc) · 880 Bytes
/
trans.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/ruby
# http://russian.moscow.usembassy.gov/transliteration.html
tr = {
' ' => ' ',
'А' => 'A',
'Б' => 'B',
'В' => 'V',
'Г' => 'G',
'Д' => 'D',
'Ж' => 'ZH',
'З' => 'Z',
'И' => 'I',
'Й' => 'Y',
'К' => 'K',
'Л' => 'L',
'М' => 'M',
'Н' => 'N',
'О' => 'O',
'П' => 'P',
'Р' => 'R',
'С' => 'S',
'Т' => 'T',
'У' => 'U',
'Ф' => 'F',
'Х' => 'KH',
'Ц' => 'TS',
'Ч' => 'CH',
'Ш' => 'SH',
'Щ' => 'SHCH',
'Ъ' => '',
'Ы' => 'Y',
'Ь' => '',
'Э' => 'E',
'Ю' => 'YU',
'Я' => 'YA',
}
input = gets.strip.split(//u)
input.each_index do |index|
sym = input[index]
if 'ЕЁ'.split(//u).include?(sym)
prev = input[index - 1]
if not prev or 'АЕЁИОУЪЫЬЭЮЯ'.split(//u).include?(prev)
res = 'YE'
else
res = 'E'
end
else
STDERR.puts 'ERROR: symbol not found (' + sym + ')' if not tr[sym]
res = tr[sym]
end
print res
end
puts