-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdecoder.rb
More file actions
49 lines (41 loc) · 1.03 KB
/
Copy pathdecoder.rb
File metadata and controls
49 lines (41 loc) · 1.03 KB
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
if !ARGV[0] then
puts "Usage: ruby ./decoder.rb %PATH_TO_RUSSIAN_FILE%"
exit!
end
selected_file = ARGV[0]
path_arr = selected_file.split('/')
file_name = path_arr.last
selected_path = selected_file.gsub(file_name, '').gsub('_en', '')
system("mkdir -p #{selected_path}")
matches = {}
File.foreach('associations.txt') do |a|
split = a.split('|')
key = split[1].strip!
matches[key] = split[0]
end
full_arr = []
File.foreach(selected_file) do |line|
word_arr = []
line.split('').each do |char|
if char != ' '
if matches[char]
word_arr.push(matches[char])
else
word_arr.push(char)
end
else
word_arr.push(char)
end
end
line_out = word_arr.join('').strip!
# puts line_out
full_arr.push(line_out)
end
output_file = selected_file.gsub('_en', '')
content = full_arr.join("\n")
File.write(output_file, content)
system("iconv -f UTF-8 -t CP437 #{output_file} -o #{output_file}.tmp -c")
system("mv #{output_file}.tmp #{output_file}")
#
# # TODO: iconv
# # TOD: move to vanilla folder