Module: Ackr

Defined in:
lib/ackr.rb,
lib/ackr/finder.rb,
lib/ackr/search.rb,
lib/ackr/colorizer.rb,
lib/ackr/formatter.rb

Defined Under Namespace

Modules: Colorizer, Finder Classes: Formatter, Search

Constant Summary collapse

EXCLUDE_DIRS =
%w(blib CVS _darcs RCS SCCS pkg tmp temp log)

Class Method Summary collapse

Class Method Details

.binary?(file) ⇒ Boolean

Method taken from: github.com/djberg96/ptools

Returns whether or not file is a binary file. Note that this is not guaranteed to be 100% accurate. It performs a “best guess” based on a simple test of the first File.blksize characters.

Example:

File.binary?(‘somefile.exe’) # => true File.binary?(‘somefile.txt’) # => false – Based on code originally provided by Ryan Davis (which, in turn, is based on Perl’s -B switch).

Returns:

  • (Boolean)


28
29
30
31
32
# File 'lib/ackr.rb', line 28

def self.binary?(file)
  str = (File.read(file, File.stat(file).blksize) || "").split(//)
  size = str.size
  ((size - str.grep(" ".."~").size) / size.to_f) > 0.30
end