useful_helpers 0.0.27 → 0.0.28

Sign up to get free protection for your applications and to get access to all the features.
@@ -10,6 +10,8 @@ require "useful_helpers/helpers/url_helper"
10
10
  require "useful_helpers/helpers/text_helper"
11
11
  require "useful_helpers/helpers/videos_helper"
12
12
 
13
+ require "untransliterate"
14
+
13
15
  module UsefulHelpers
14
16
  class Engine < ::Rails::Engine
15
17
  isolate_namespace UsefulHelpers
@@ -0,0 +1,63 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ module Untransliterate
4
+ RV_LOWER_SINGLE = {
5
+ "і"=>"i","ґ"=>"g","ё"=>"yo","№"=>"#","є"=>"e",
6
+ "ї"=>"yi","а"=>"a","б"=>"b",
7
+ "в"=>"v","г"=>"g","д"=>"d","е"=>"e","ж"=>"zh",
8
+ "з"=>"z","и"=>"i","й"=>"y","к"=>"k","л"=>"l",
9
+ "м"=>"m","н"=>"n","о"=>"o","п"=>"p","р"=>"r",
10
+ "с"=>"s","т"=>"t","у"=>"u","ф"=>"f","х"=>"h",
11
+ "ц"=>"ts","ч"=>"ch","ш"=>"sh","щ"=>"sch","ъ"=>"'",
12
+ "ы"=>"y","ь"=>"","э"=>"e","ю"=>"yu","я"=>"ya",
13
+ }.invert
14
+
15
+ RV_LOWER_MULTI = {
16
+ # "ье"=>"ie",
17
+ # "ьё"=>"ie",
18
+ }.invert
19
+
20
+ RV_UPPER_SINGLE = {
21
+ "Ґ"=>"G","Ё"=>"YO","Є"=>"E","Ї"=>"YI","І"=>"I",
22
+ "А"=>"A","Б"=>"B","В"=>"V","Г"=>"G",
23
+ "Д"=>"D","Е"=>"E","Ж"=>"ZH","З"=>"Z","И"=>"I",
24
+ "Й"=>"Y","К"=>"K","Л"=>"L","М"=>"M","Н"=>"N",
25
+ "О"=>"O","П"=>"P","Р"=>"R","С"=>"S","Т"=>"T",
26
+ "У"=>"U","Ф"=>"F","Х"=>"H","Ц"=>"TS","Ч"=>"CH",
27
+ "Ш"=>"SH","Щ"=>"SCH","Ъ"=>"'","Ы"=>"Y","Ь"=>"",
28
+ "Э"=>"E","Ю"=>"YU","Я"=>"YA",
29
+ }.invert
30
+
31
+ RV_UPPER_MULTI = {
32
+ # "ЬЕ"=>"IE",
33
+ # "ЬЁ"=>"IE",
34
+ }.invert
35
+
36
+ RV_LOWER = (LOWER_SINGLE.merge(RV_LOWER_MULTI)).freeze
37
+ RV_UPPER = (UPPER_SINGLE.merge(RV_UPPER_MULTI)).freeze
38
+ RV_MULTI_KEYS = (LOWER_MULTI.merge(RV_UPPER_MULTI)).keys.sort_by {|s| s.length}.reverse.freeze
39
+
40
+ # Transliterate a string with russian characters
41
+ #
42
+ # Возвращает строку, в которой все буквы русского алфавита заменены на похожую по звучанию латиницу
43
+ def self.run(str)
44
+ chars = str.scan(%r{#{RV_MULTI_KEYS.join '|'}|\w|.})
45
+
46
+ result = ""
47
+
48
+ chars.each_with_index do |char, index|
49
+ if RV_UPPER.has_key?(char) && RV_LOWER.has_key?(chars[index+1])
50
+ # combined case
51
+ result << RV_UPPER[char].downcase.capitalize
52
+ elsif UPPER.has_key?(char)
53
+ result << RV_UPPER[char]
54
+ elsif LOWER.has_key?(char)
55
+ result << RV_LOWER[char]
56
+ else
57
+ result << char
58
+ end
59
+ end
60
+
61
+ result
62
+ end
63
+ end
@@ -1,3 +1,3 @@
1
1
  module UsefulHelpers
2
- VERSION = "0.0.27"
2
+ VERSION = "0.0.28"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: useful_helpers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.27
4
+ version: 0.0.28
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-09-01 00:00:00.000000000 Z
12
+ date: 2013-10-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -89,6 +89,7 @@ files:
89
89
  - lib/useful_helpers/helpers/text_helper.rb
90
90
  - lib/useful_helpers/helpers/url_helper.rb
91
91
  - lib/useful_helpers/helpers/videos_helper.rb
92
+ - lib/useful_helpers/untransliterate.rb
92
93
  - lib/useful_helpers/version.rb
93
94
  - useful_helpers.gemspec
94
95
  homepage: https://github.com/st-granat/useful_helpers