README

Last Update: Mon May 21 16:17:29 -0600 2007

Description

The ptools (power tools) package is an additional set of commands for the File class based on Unix command line tools.

Prerequisites

Ruby 1.8.0 or later is recommended but not required.
On MS Windows you will need win32-file 0.5.4 or later.

Installation

Gem

ruby ptools.gemspec
gem install ptools-x.y.z.gem

Manual

rake test (optional)
rake install

Synopsis

   
   require "ptools"

   File.which("ruby")         # '/usr/local/bin/ruby'
   File.whereis("ruby")       # ['/usr/local/bin/ruby','/opt/bin/ruby']

   File.head("myfile")        # Returns first 10 lines of 'myfile'
   File.middle("myfile",8,12) # Returns lines 8-12 of 'myfile'
   File.tail("myfile",3)      # Returns last 3 lines of 'myfile'
   File.wc("myfile",'words')  # Returns the number of words in 'myfile'

   File.touch("newfile")      # "newfile" now exists
   File.null                  # '/dev/null' on Unix, 'NUL' on Windows
   File.binary?('some_file')  # true or false

   # Creates a copy of 'myfile' called 'newfile', in DOS format
   File.nl_convert("myfile", "newfile", "dos")
   

Known Bugs

There is a bug in 1.6.x that can cause $\ characters to accumulate when converting to DOS or MAC format if nl_convert is run multiple times on the same file. This appears to be fixed in 1.8.x.

One or two of The File.nl_convert tests may fail on Windows. You can ignore these.

Acknowledgements

The which() method was adopted from the FileWhich code posted by Michael Granger on http://www.rubygarden.org. The 'whereis' command is a minor modification of that code as well.

The nl_convert() method was adopted (somewhat) from the nlcvt program found at http://www.perl.com/language/ppt/src/nlcvt/nlcvt, written by Tom Christiansen.

The middle() method was provided by Shashank Date.

The binary?() method was based almost entirely on a blog post by Ryan Davis (who, in turn, based his code on Perl's -B switch).

Future Plans

Add whatever other tools people think might be useful.

License

Ruby's

Copyright

(C) 2003-2007 Daniel J. Berger
All Rights Reserved.

Warranty

This package is provided "as is" and without any exblockquotess or implied warranties, including, without limitation, the implied warranties of merchantability and fitness for a particular purpose.

Author

Daniel J. Berger
djberg96 at nospam at gmail dot com
imperator on IRC (irc.freenode.net)

[Validate]