translit_net 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/translit_net.rb +49 -0
  3. metadata +44 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7dc53eaf42be6d62ddb0c0a4818f2bd685c8a20a
4
+ data.tar.gz: 13d20a1ea4fe8ad6929788e105abc0901a07f937
5
+ SHA512:
6
+ metadata.gz: f0d96ca981ca815353ff95356bd95eac3f0bca4f4a2fa7ffebd5418eda9c024e69512861d8e5aafa82e73bcf7f12882391c1ec76441d806d2df1d8ce07906bce
7
+ data.tar.gz: 2b2315fda608bdf1d0a561f7fa5668bcb6bb0b3ee114bce9ace5444248b6709466cdc34209a9a8a0cc1dfce4fb24e88b169951ea375c9f3ee83723af30f4669c
@@ -0,0 +1,49 @@
1
+ # coding: utf-8
2
+ class String
3
+
4
+ EN_RU = {}
5
+
6
+ RU_EN = {
7
+ 'А' => 'A', 'а' => 'a', 'Б' => 'B', 'б' => 'b', 'В' => 'V', 'в' => 'v', 'Г' => 'G', 'г' => 'g', 'Д' => 'D', 'д' => 'd',
8
+ 'Е' => 'E', 'е' => 'e', 'Ё' => 'Jo', 'ё' => 'jo', 'Ж' => 'Zh', 'ж' => 'zh', 'З' => 'Z', 'з' => 'z', 'И' => 'I',
9
+ 'и' => 'i', 'Й' => 'J', 'й' => 'j', 'К' => 'K', 'к' => 'k', 'Л' => 'L', 'л' => 'l', 'М' => 'M', 'м' => 'm', 'Н' => 'N',
10
+ 'н' => 'n', 'О' => 'O', 'о' => 'o', 'П' => 'P', 'п' => 'p', 'Р' => 'R', 'р' => 'r', 'С' => 'S', 'с' => 's', 'Т' => 'T',
11
+ 'т' => 't', 'У' => 'U', 'у' => 'u', 'Ф' => 'F', 'ф' => 'f', 'Х' => 'H', 'х' => 'h', 'Ц' => 'C', 'ц' => 'c', 'Ч' => 'Ch',
12
+ 'ч' => 'ch', 'Щ' => 'Shh', 'щ' => 'shh', 'Ш' => 'Sh', 'ш' => 'sh', 'Ы' => 'Y', 'ы' => 'y', 'Ь' => "''", 'ь' => "'",
13
+ 'Ъ' => '##', 'ъ' => '#', 'Э' => 'Je', 'э' => 'je', 'Ю' => 'Ju', 'ю' => 'ju', 'Я' => 'Ja', 'я' => 'ja'
14
+ }
15
+
16
+ UA_EN = {
17
+ 'А' => 'A', 'а' => 'a', 'Б' => 'B', 'б' => 'b', 'В' => 'V', 'в' => 'v', 'Г' => 'G', 'г' => 'g', 'Ґ' => "G'", 'ґ' => "g'",
18
+ 'Д' => 'D', 'д' => 'd', 'Е' => 'E', 'е' => 'e', 'Є' => 'Je', 'є' => 'je', 'Ж' => 'Zh', 'ж' => 'zh', 'З' => 'Z', 'з' => 'z',
19
+ 'И' => 'Y', 'и' => 'y', 'І' => 'I', 'і' => 'i', 'Ї' => "I'", 'ї' => "i'", 'Й' => 'J', 'й' => 'j', 'К' => 'K', 'к' => 'k',
20
+ 'Л' => 'L', 'л' => 'l', 'М' => 'M', 'м' => 'm', 'Н' => 'N', 'н' => 'n', 'О' => 'O', 'о' => 'o', 'П' => 'P', 'п' => 'p',
21
+ 'Р' => 'R', 'р' => 'r', 'С' => 'S', 'с' => 's', 'Т' => 'T', 'т' => 't', 'У' => 'U', 'у' => 'u', 'Ф' => 'F', 'ф' => 'f',
22
+ 'Х' => 'H', 'х' => 'h', 'Ц' => 'C', 'ц' => 'c', 'Ч' => 'Ch', 'ч' => 'ch', 'Щ' => 'Shh', 'щ' => 'shh', 'Ш' => 'Sh', 'ш' => 'sh',
23
+ 'Ы' => 'Y', 'ы' => 'y', 'Ь' => "''", 'ь' => "'", 'Э' => 'Je', 'э' => 'je', 'Ю' => 'Ju', 'ю' => 'ju', 'Я' => 'Ja', 'я' => 'ja'
24
+ }
25
+
26
+ def translit(options = { from: 'en', to: 'ru' })
27
+ h = EN_RU
28
+ h = if ru_en?(options)
29
+ RU_EN
30
+ elsif ua_en?(options)
31
+ UA_EN
32
+ end
33
+
34
+ self.split('').map do |char|
35
+ h[char] ? h[char] : char
36
+ end.join('')
37
+ end
38
+
39
+ private
40
+
41
+ def ru_en?(options)
42
+ options && options[:from] == 'ru' && options[:to] == 'en'
43
+ end
44
+
45
+ def ua_en?(options)
46
+ options && options[:from] == 'ua' && options[:to] == 'en'
47
+ end
48
+
49
+ end
metadata ADDED
@@ -0,0 +1,44 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: translit_net
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Maksim Berjoza
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-04 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Transliterate ru, ua, en
14
+ email: maksim.berjoza@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/translit_net.rb
20
+ homepage: https://github.com/torbjon/translit_net
21
+ licenses:
22
+ - MIT
23
+ metadata: {}
24
+ post_install_message:
25
+ rdoc_options: []
26
+ require_paths:
27
+ - lib
28
+ required_ruby_version: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ required_rubygems_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ requirements: []
39
+ rubyforge_project:
40
+ rubygems_version: 2.2.2
41
+ signing_key:
42
+ specification_version: 4
43
+ summary: TranlistNet
44
+ test_files: []