Monday, 2 November 2015

Detect file encoding to current dir .rb files

encodings = []
not_utf8 = []
Dir.glob(Dir.new(".").path + '/**/*.rb') do |file|
contents = File.read(file)
detection = CharlockHolmes::EncodingDetector.detect(contents)
encodings << detection[:encoding]
not_utf8 << {file: file, detection: detection} unless "UTF-8" == detection[:encoding]
end
pp encodings.uniq
pp not_utf8
view raw gistfile1.rb hosted with ❤ by GitHub

No comments:

Post a Comment