Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/assetify/extensions/string.rb
Overview
Adapted ptools - rdoc.info/gems/ptools/1.2.1/File.binary%3F
Instance Method Summary collapse
Instance Method Details
#binary? ⇒ Boolean
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/assetify/extensions/string.rb', line 5 def binary? # s = (File.read(file, File.stat(file).blksize) || "").split(//) s = (self[0..4096].force_encoding('binary') || '') # .split(//) ratio = s.gsub(/\d|\w|\s|[-~\.]/, '').size / s.size.to_f # if Opt[:debug] # print "Detecting #{s}" # puts "Ratio #{ratio}" # end ratio > 0.3 end |