Skip to content

Commit 797fe6d

Browse files
committed
update Ruby example
1 parent d32ff8d commit 797fe6d

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

example-ruby/words.rb

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,21 @@
1111

1212
sorted = false
1313

14-
paths = Dir['../data/pl/**/*.yml']
14+
paths = Dir['../data/??/**/*.yml']
15+
total_size = 0
16+
count = paths.count
1517

16-
Parallel.each(paths, in_processes: Etc.nprocessors) do |yaml_path|
18+
Parallel.each_with_index(paths, in_processes: Etc.nprocessors) do |yaml_path, i|
1719
meta = YAML.load_file(yaml_path)
1820
words = IO.read(yaml_path.gsub('.yml', '.txt')).downcase.strip.split(/[^\p{word}]+/).uniq
19-
if sorted
20-
words = words.sort
21-
end
21+
words = words.sort if sorted
22+
total_size += words.count
2223
outpath = "#{outdir}/#{meta['lang']}-#{meta['code']}.txt"
23-
puts outpath
24+
# puts "[#{i}/#{count}] #{yaml_path}/#{outpath}"
25+
puts(format('[%3d/%d] %s/%s', i, count, yaml_path, outpath))
2426
File.write(outpath, words.join("\n"))
2527
end
2628

2729
secs = Time.now - start
30+
puts "Total size: #{total_size}"
2831
puts "Total time: #{secs} s"
29-

0 commit comments

Comments
 (0)