etvnet_seek 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +5 -1
- data/bin/etvnet_seek +8 -2
- data/etvnet_seek.gemspec +1 -1
- data/lib/main.rb +1 -0
- data/lib/runglish.rb +122 -33
- data/spec/etvnet_seek_spec.rb +3 -2
- metadata +1 -1
data/CHANGES
CHANGED
data/bin/etvnet_seek
CHANGED
@@ -11,13 +11,19 @@ require 'main'
|
|
11
11
|
|
12
12
|
client = Main.new
|
13
13
|
|
14
|
-
|
14
|
+
keywords = ARGV.join(' ')
|
15
|
+
|
16
|
+
if RUBY_PLATFORM =~ /mswin32/
|
17
|
+
keywords = Runglish.new.lat_to_ru(keywords)
|
18
|
+
end
|
19
|
+
|
20
|
+
movie_link = client.search_and_grab_link keywords
|
15
21
|
|
16
22
|
if movie_link
|
17
23
|
puts "Link: #{movie_link}"
|
18
24
|
|
19
25
|
if RUBY_PLATFORM =~ /(win|w)32$/
|
20
|
-
`wmplayer #{movie_link}`
|
26
|
+
`start wmplayer #{movie_link}`
|
21
27
|
elsif RUBY_PLATFORM =~ /darwin/
|
22
28
|
`open #{movie_link}`
|
23
29
|
end
|
data/etvnet_seek.gemspec
CHANGED
data/lib/main.rb
CHANGED
data/lib/runglish.rb
CHANGED
@@ -2,42 +2,131 @@
|
|
2
2
|
#
|
3
3
|
# Runglish stands for Russian text in Latin letters.
|
4
4
|
|
5
|
+
# -*- encoding: utf-8 -*-
|
6
|
+
|
7
|
+
if RUBY_VERSION < "1.9"
|
8
|
+
$KCODE = 'u'
|
9
|
+
end
|
10
|
+
|
5
11
|
class Runglish
|
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
|
-
|
12
|
+
|
13
|
+
LOWER_SINGLE = {
|
14
|
+
"і"=>"i", "ґ"=>"g", "ё"=>"yo", "№"=>"#", "є"=>"e", "ї"=>"yi",
|
15
|
+
"а"=>"a", "б"=>"b", "в"=>"v", "г"=>"g", "д"=>"d", "е"=>"e", "ж"=>"zh",
|
16
|
+
"з"=>"z", "и"=>"i", "й"=>"y", "к"=>"k", "л"=>"l", "м"=>"m", "н"=>"n", "о"=>"o", "п"=>"p", "р"=>"r",
|
17
|
+
"с"=>"s", "т"=>"t", "у"=>"u", "ф"=>"f", "х"=>"h", "ц"=>"ts", "ч"=>"ch", "ш"=>"sh", "щ"=>"sch",
|
18
|
+
"ъ"=>"'", "ы"=>"y", "ь"=>"", "э"=>"e", "ю"=>"yu", "я"=>"ya",
|
19
|
+
}
|
20
|
+
|
21
|
+
LOWER_MULTI = {
|
22
|
+
"ье"=>"ie",
|
23
|
+
"ьё"=>"ie",
|
24
|
+
}
|
25
|
+
|
26
|
+
UPPER_SINGLE = {
|
27
|
+
"Ґ"=>"G", "Ё"=>"YO", "Є"=>"E", "Ї"=>"YI", "І"=>"I",
|
28
|
+
"А"=>"A", "Б"=>"B", "В"=>"V", "Г"=>"G", "Д"=>"D", "Е"=>"E", "Ж"=>"ZH",
|
29
|
+
"З"=>"Z", "И"=>"I", "Й"=>"Y", "К"=>"K", "Л"=>"L", "М"=>"M", "Н"=>"N", "О"=>"O", "П"=>"P", "Р"=>"R",
|
30
|
+
"С"=>"S", "Т"=>"T", "У"=>"U", "Ф"=>"F", "Х"=>"H", "Ц"=>"TS", "Ч"=>"CH", "Ш"=>"SH", "Щ"=>"SCH",
|
31
|
+
"Ъ"=>"'", "Ы"=>"Y", "Ь"=>"", "Э"=>"E", "Ю"=>"YU", "Я"=>"YA",
|
32
|
+
}
|
33
|
+
|
34
|
+
UPPER_MULTI = {
|
35
|
+
"ЬЕ"=>"IE",
|
36
|
+
"ЬЁ"=>"IE",
|
37
|
+
}
|
38
|
+
|
39
|
+
LOWER = (LOWER_SINGLE.merge(LOWER_MULTI)).freeze
|
40
|
+
UPPER = (UPPER_SINGLE.merge(UPPER_MULTI)).freeze
|
41
|
+
MULTI_KEYS = (LOWER_MULTI.merge(UPPER_MULTI)).keys.sort_by {|s| s.length}.reverse.freeze
|
42
|
+
|
43
|
+
|
44
|
+
LOWER_SINGLE_2 = {
|
45
|
+
"i"=>"і", "g"=>"ґ", "#"=>"№", "e"=>"є",
|
46
|
+
"a"=>"а", "b"=>"б", "v"=>"в", "g"=>"г", "d"=>"д", "e"=>"е", "z"=>"з", "i"=>"и", "y"=>"й",
|
47
|
+
"k"=>"к", "l"=>"л", "m"=>"м", "n"=>"н", "o"=>"о", "p"=>"п", "r"=>"р", "s"=>"с", "t"=>"т",
|
48
|
+
"u"=>"у", "f"=>"ф", "h"=>"х", "'"=>"ъ", "y"=>"ы", "e"=>"э"
|
49
|
+
}
|
50
|
+
LOWER_MULTI_2 = {
|
51
|
+
"yo"=>"ё",
|
52
|
+
"yi"=>"ї",
|
53
|
+
"zh"=>"ж",
|
54
|
+
"ts"=>"ц",
|
55
|
+
"ch"=>"ч",
|
56
|
+
"sh"=>"ш",
|
57
|
+
"sch"=>"щ",
|
58
|
+
"yu"=>"ю",
|
59
|
+
"ya"=>"я",
|
60
|
+
"ie"=>"ье"
|
61
|
+
}
|
62
|
+
|
63
|
+
UPPER_SINGLE_2 = {
|
64
|
+
"G"=>"Ґ", "Є"=>"E", "I"=>"І",
|
65
|
+
"A"=>"А", "B"=>"Б", "V"=>"В", "G"=>"Г", "D"=>"Д", "E"=>"Е", "Z"=>"З", "I"=>"И",
|
66
|
+
"Y"=>"Й", "K"=>"К", "L"=>"Л", "M"=>"М", "N"=>"Н", "O"=>"О", "P"=>"П", "R"=>"Р",
|
67
|
+
"S"=>"С", "T"=>"Т", "U"=>"У", "F"=>"Ф", "H"=>"Х", "'"=>"Ъ", "Y"=>"Ы", "E"=>"Э"
|
68
|
+
}
|
69
|
+
|
70
|
+
UPPER_MULTI_2 = {
|
71
|
+
"YO"=>"Ё",
|
72
|
+
"YI"=>"Ї",
|
73
|
+
"ZH"=>"Ж",
|
74
|
+
"TS"=>"Ц",
|
75
|
+
"CH"=>"Ч",
|
76
|
+
"SH"=>"Ш",
|
77
|
+
"SCH"=>"Щ",
|
78
|
+
"YU"=>"Ю",
|
79
|
+
"YA"=>"Я",
|
80
|
+
"IE"=>"ЬЕ"
|
81
|
+
}
|
82
|
+
|
83
|
+
LOWER_2 = (LOWER_SINGLE_2.merge(LOWER_MULTI_2)).freeze
|
84
|
+
UPPER_2 = (UPPER_SINGLE_2.merge(UPPER_MULTI_2)).freeze
|
85
|
+
MULTI_KEYS_2 = (LOWER_MULTI_2.merge(UPPER_MULTI_2)).keys.sort_by {|s| s.length}.reverse.freeze
|
86
|
+
|
87
|
+
# Transliterate a string with russian characters
|
88
|
+
#
|
89
|
+
# Возвращает строку, в которой все буквы русского алфавита заменены на похожую по звучанию латиницу
|
90
|
+
def ru_to_lat(str)
|
91
|
+
chars = str.scan(%r{#{MULTI_KEYS.join '|'}|\w|.})
|
92
|
+
|
93
|
+
result = ""
|
94
|
+
|
95
|
+
chars.each_with_index do |char, index|
|
96
|
+
if UPPER.has_key?(char) && LOWER.has_key?(chars[index+1])
|
97
|
+
# combined case
|
98
|
+
result << UPPER[char].downcase.capitalize
|
99
|
+
elsif UPPER.has_key?(char)
|
100
|
+
result << UPPER[char]
|
101
|
+
elsif LOWER.has_key?(char)
|
102
|
+
result << LOWER[char]
|
103
|
+
else
|
104
|
+
result << char
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
result
|
109
|
+
end
|
110
|
+
|
111
|
+
def lat_to_ru(str)
|
112
|
+
chars = str.scan(%r{#{MULTI_KEYS_2.join '|'}|\w|.})
|
113
|
+
|
114
|
+
result = ""
|
115
|
+
|
116
|
+
chars.each_with_index do |char, index|
|
117
|
+
if UPPER_2.has_key?(char) && LOWER_2.has_key?(chars[index+1])
|
118
|
+
# combined case
|
119
|
+
result << UPPER_2[char].downcase.capitalize
|
120
|
+
elsif UPPER_2.has_key?(char)
|
121
|
+
result << UPPER_2[char]
|
122
|
+
elsif LOWER_2.has_key?(char)
|
123
|
+
result << LOWER_2[char]
|
124
|
+
else
|
125
|
+
result << char
|
126
|
+
end
|
38
127
|
end
|
39
128
|
|
40
|
-
|
129
|
+
result
|
41
130
|
end
|
42
131
|
end
|
43
132
|
|
data/spec/etvnet_seek_spec.rb
CHANGED
@@ -27,7 +27,8 @@ end
|
|
27
27
|
|
28
28
|
describe Runglish do
|
29
29
|
it "should return translation" do
|
30
|
-
Runglish.new.translate("kak dela?").size.should > 0
|
31
|
-
p Runglish.new.
|
30
|
+
#Runglish.new.translate("kak dela?").size.should > 0
|
31
|
+
p Runglish.new.ru_to_lat("как дела?")
|
32
|
+
p Runglish.new.lat_to_ru("krasnaya shapochka")
|
32
33
|
end
|
33
34
|
end
|