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 CHANGED
@@ -7,4 +7,8 @@
7
7
 
8
8
  == Version 0.2.0
9
9
 
10
- * Bug fixes, code for Windows
10
+ * Bug fixes, code for Windows
11
+
12
+ == Version 0.3.0
13
+
14
+ * Bug fixes, support for Runglish (you can enter russian string as latin one)
data/bin/etvnet_seek CHANGED
@@ -11,13 +11,19 @@ require 'main'
11
11
 
12
12
  client = Main.new
13
13
 
14
- movie_link = client.search_and_grab_link ARGV.join(' ')
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
@@ -4,7 +4,7 @@ require "rake"
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = %q{etvnet_seek}
7
- s.version = "0.2.0"
7
+ s.version = "0.3.0"
8
8
 
9
9
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
10
10
 
data/lib/main.rb CHANGED
@@ -5,6 +5,7 @@ require "highline/import"
5
5
 
6
6
  require 'cookie_helper'
7
7
  require 'url_seeker'
8
+ require 'runglish'
8
9
 
9
10
  class Main
10
11
  include CookieHelper
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
- RUSSIAN_TABLE = [
7
- '\u0430', '\u0431', '\u0432', '\u0433', '\u0434', '\u0435', '\u0436', '\u0437',
8
- '\u0438', '\u0439', '\u043a', '\u043b', '\u043c', '\u043d', '\u043e', '\u043f',
9
- '\u0440', '\u0441', '\u0442', '\u0443', '\u0444', '\u0445', '\u0446', '\u0447',
10
- '\u0448', '\u0449', '\u044a', '\u044b', '\u044c', '\u044d', '\u044e', '\u044f',
11
- '\u0451',
12
- '\u0401',
13
- '\u0410', '\u0411', '\u0412', '\u0413', '\u0414', '\u0415', '\u0416', '\u0417',
14
- '\u0418', '\u0419', '\u041a', '\u041b', '\u041c', '\u041d', '\u041e', '\u041f',
15
- '\u0420', '\u0421', '\u0422', '\u0423', '\u0424', '\u0425', '\u0426', '\u0427',
16
- '\u0428', '\u0429', '\u042a', '\u042b', '\u042c', '\u042d', '\u042e', '\u042f'
17
- ]
18
-
19
-
20
- ENGLISH_TABLE = [
21
- "a", "b", "v", "g", "d", "e", "zh", "z", "i", "y", "k", "l", "m", "n", "o", "p", "r",
22
- "s", "t", "u", "f", "h", "c", "ch", "sh", "s'h", "''", "yi", "'", "ye", "yu", "ya",
23
- "yo",
24
- "YO",
25
- "A", "B", "V", "G", "D", "E", "Zh", "Z", "I", "Y", "K", "L", "M", "N", "O", "P", "R",
26
- "S", "T", "U", "F", "H", "C", "Ch", "Sh", "S'h", "''", "Yi", "'", "Ye", "Yu", "Ya"
27
- ]
28
-
29
- ENGLISH_RUSSIAN_MAP = Hash[*ENGLISH_TABLE.zip(RUSSIAN_TABLE).flatten]
30
-
31
- def translate(old_text)
32
- new_text = ""
33
-
34
- old_text.each_char do |ch|
35
- new_ch = ENGLISH_RUSSIAN_MAP[ch].nil? ? ch : ENGLISH_RUSSIAN_MAP[ch]
36
-
37
- new_text += new_ch
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
- new_text
129
+ result
41
130
  end
42
131
  end
43
132
 
@@ -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.translate("kak dela?")
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: etvnet_seek
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Shvets