Class File
In: ptools.rb
Parent: Object

Methods

binary?   head   image?   middle   nl_convert   null   tail   touch   wc   whereis   which  

Constants

PTOOLS_VERSION = '1.1.5'

Public Class methods

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.

In block form, yields the first num_lines from filename. In non-block form, returns an Array of num_lines

Returns whether or not the file is an image. Only JPEG, PNG, BMP and GIF are checked against.

This method does some simple read and extension checks. For a version that is more robust, but which depends on a 3rd party C library (and is difficult to build on MS Windows), see the ‘filemagic’ library, available on the RAA.

In block form, yields line from up to line to. In non-block form returns an Array of lines from from to to.

Converts a text file from one OS platform format to another, ala ‘dos2unix’. Valid values for ‘format’, which are case insensitve, include:

  • MS Windows -> dos, windows, win32, mswin
  • Unix/BSD -> unix, linux, bsd
  • Mac -> mac, macintosh, apple, osx

Note that this method is only valid for an ftype of "file". Otherwise a TypeError will be raised. If an invalid format value is received, an ArgumentError is raised.

Returns the null device (aka bitbucket) on your platform. On most Unix-like systems this is ’/dev/null’, on Windows it‘s ‘NUL’, etc.

In block form, yields the last num_lines of file filename. In non-block form, it returns the lines as an array.

Note that this method slurps the entire file, so I don‘t recommend it for very large files. Also note that ‘tail -f’ functionality is not present.

Creates the 0 byte file filename.

With no arguments, returns a four element array consisting of the number of bytes, characters, words and lines in filename, respectively.

Valid options are ‘bytes’, ‘characters’ (or just ‘chars’), ‘words’ and ‘lines’.

In block form, yields each program within path. In non-block form, returns an array of each program within path.

On Windows, it looks for executables ending with the suffixes defined in your PATHEXT environment variable, or ’.exe’, ’.bat’ and ’.com’ if that isn‘t defined, which you may optionally include in program.

Returns nil if not found.

Looks for the first occurrence of program within path.

On Windows, it looks for executables ending with the suffixes defined in your PATHEXT environment variable, or ’.exe’, ’.bat’ and ’.com’ if that isn‘t defined, which you may optionally include in program.

Returns nil if not found.

[Validate]