Sha256: ecfb3c602f14505b5e89588efe22dd4a2b5fcffdb4114e4922bcfa4def8544a0
Contents?: true
Size: 1.3 KB
Versions: 8
Compression:
Stored size: 1.3 KB
Contents
Rule Main input ('*.txt' or 'terminate.cmd').except('summary.txt').all output '*.count'.all output 'summary.txt' Flow rule CountChar rule Summarize End Rule CountChar input '*.txt'.except('summary.txt') output '{$*}.count' Flow rule ConvertToUtf8 rule CountUTF8Char rule Terminate End Rule ConvertToUtf8 input '*.txt'.except('summary.txt') output '{$*}.utf8' Action iconv -c -f Shift_JIS -t UTF-8 {$I[1]} > {$O[1]} End Rule CountUTF8Char input '*.utf8' output '{$*}.count'.stdout Action #!/usr/bin/env ruby # coding: utf-8 table = {} text = File.open("{$I[1]}").read text.split("").each do |c| table[c] = table.has_key?(c) ? table[c].succ : 1 end table.keys.sort {|a,b| table[b] <=> table[a] }.each do |key| puts "#{key.inspect[1..-2]}:#{table[key]}" end End Rule Summarize input '*.count'.all output 'summary.txt'.stdout Action #!/usr/bin/env ruby # coding: utf-8 table = {} "{$I[1]}".split(":").each do |path| File.read(path).split("\n").map do |line| c, number = line.split(":") table[c] = (table.has_key?(c) ? table[c] : 0) + number.to_i end end table.keys.sort {|a,b| table[b] <=> table[a] }.each do |key| puts "#{key.inspect[1..-2]}:#{table[key]}" end End Rule Terminate input 'terminate.cmd' Flow rule &system:Terminate End
Version data entries
8 entries across 8 versions & 1 rubygems