From: Corey Lawson Date: 2005-09-08T12:47:04+09:00 Subject: Re: [ANN] Rio 0.3.4 ------=_Part_13052_20355439.1126151221993 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Will a modification of IRB with RIO, and a few other things, possibly resul= t=20 in a "ruby shell" that blows Monad away (but results in scripts that are=20 more or less portable between Win32, MacOS, and *nix? On 9/6/05, rio4ruby wrote: >=20 > New and Improved -- Rio 0.3.4 >=20 > =3D=3D Overview >=20 > Rio is a Ruby I/O convenience class wrapping much of the functionality > of IO, File and Dir. Rio also uses FileUtils, Tempfile, StringIO, > OpenURI, Zlib, and CSV to provide similar functionality using a simple > consistent interface. In addition to forwarding the interfaces > provided by IO, File, and Dir to an appropriate object, Rio provides a > "grande" interface that allows many common application-level I/O and > file-system tasks to be expressed succinctly. >=20 > =3D=3D SYNOPSIS >=20 > For the following assume: > astring =3D "" > anarray =3D [] >=20 > Copy or append a file to a string > rio('afile') > astring # copy > rio('afile') >> astring # append >=20 > Copy or append a string to a file > rio('afile') < astring # copy > rio('afile') << astring # append >=20 > Copy or append the lines of a file to an array > rio('afile') > anarray > rio('afile') >> anarray >=20 > Copy or append a file to another file > rio('afile') > rio('another_file') > rio('afile') >> rio('another_file') >=20 > Copy a file to a directory > rio('adir') << rio('afile') >=20 > Copy a directory structure to another directory > rio('adir') >> rio('another_directory') >=20 > Copy a web-page to a file > rio('http://rubydoc.org/') > rio('afile') >=20 > Ways to get the chomped lines of a file into an array > anarray =3D rio('afile').chomp[] # subscript operator > rio('afile').chomp > anarray # copy-to operator > anarray =3D rio('afile').chomp.to_a # to_a > anarray =3D rio('afile').chomp.readlines # IO#readlines >=20 > Copy a gzipped file un-gzipping it > rio('afile.gz').gzip > rio('afile') >=20 > Copy a plain file, gzipping it > rio('afile.gz').gzip < rio('afile') >=20 > Copy a file from a ftp server into a local file un-gzipping it > rio('ftp://host/afile.gz').gzip > rio('afile') >=20 > Iterate over the entries in a directory > rio('adir').entries { |entrio| ... } >=20 > Iterate over only the files in a directory > rio('adir').files { |entrio| ... } >=20 > Iterate over only the .rb files in a directory > rio('adir').files('*.rb') { |entrio| ... } >=20 > Iterate over .rb files but not symlinks to .rb files > rio('adir').files('*.rb').skip(:symlink?) { |entrio| ... } >=20 > Iterate over only the _dot_ files in a directory > rio('adir').files(/^\./) { |entrio| ... } >=20 > Iterate over the files in a directory and its subdirectories, skipping > '.svn' and 'CVS' directories >=20 > rio('adir').norecurse(/^\.svn$/,'CVS').files { |entrio| ... } >=20 > Create an array of the .rb entries in a directory > anarray =3D rio('adir')['*.rb'] >=20 > Create an array of the .rb entries in a directory and its > subdirectories. > anarray =3D rio('adir').all['*.rb'] >=20 > Iterate over the .rb files in a directory and its subdirectories > rio('adir').all.files('*.rb') { |entrio| ... } >=20 > Iterate over the non-empty, non-comment chomped lines of a file > rio('afile').chomp.skip.lines(:empty?,/^\s*#/) { |line| ... } >=20 > Copy the output of th ps command into an array, skipping the header > line and the ps command entry > rio(?-,'ps -a').skip.lines(0,/ps$/) > anarray >=20 > Prompt for input and return what was typed > ans =3D rio(?-).print("Type Something: ").chomp.gets >=20 > Change the extension of all .htm files in a directory and its > subdirectories to .html > rio('adir').rename.all.files('*.htm') do |htmfile| > htmfile.extname =3D '.html' > end >=20 > Create a symbolic link 'asymlink' in 'adir' which refers to > 'adir/afile' > rio('adir/afile').symlink('adir/asymlink') >=20 > Copy a CSV file, changing the separator to a semicolon > rio('comma.csv').csv > rio('semicolon.csv').csv(';') >=20 > Iterate through a CSVfile with each line parsed into an array > rio('afile.csv').csv { |array_of_fields| ...} >=20 > Create a tab separated file of accounts in a UNIX passwd file, > listing only the username, uid, and realname fields > rio('/etc/passwd').csv(':').columns(0,2,4) > rio('rpt').csv("\t") >=20 > =3D=3D New for version 0.3.4 >=20 > * New Grande Selection parameter. >=20 > A major weakness of Rio's selection methods (lines, files, etc.) > has always been that it only implemented a logical OR. >=20 > rio('afile').lines(0..10,/Rio/) {...} > iterates through lines that are in the range 0..10 OR > contain 'Rio'. >=20 > rio('adir').files(:executable?,'*.rb') {...} > iterates through files that are executable OR match '*.rb' >=20 > Selecting files that matched both required using a proc. > rio('adir').files(proc{ |f| f.executable? and f.fnmatch?('*.rb')}) > {...} >=20 > Rio's grande selection methods will now accept an array of conditions > which must all be matched, in order to be selected. A logical AND. >=20 > rio('adir').files([:executable?,'*.rb']) {...} >=20 > The array, of course, need not be the only paramter. >=20 > rio('adir').files('*.exe',[:executable?,'*.rb']) {...} >=20 > selects .exe files and .rb files that are executable. >=20 > * Renamed some of grande rejection methods. > (based on a suggestion by Gavin Sinclair) > nolines =3D> skiplines > nofiles =3D> skipfiles > etc. >=20 > * New skip() grande method > rio('afile').skip.lines(/Rio/) # same as skiplines(/Rio/) > rio('afile').lines(/Rio/).skip(0..9) # lines with 'Rio', exclude > # the first ten lines >=20 > * Alternative syntaxes for creating Rios that have no path. > rio(?-) # create a Rio refering to stdio > rio(:stdio) # same thing. > rio.stdio # same thing > RIO.stdio # ditto > RIO::Rio.stdio # once again >=20 > * From Pathname added > * root? > * mountpoint? > * realpath > * cleanpath >=20 > * Removed Rio#slurp in favor of Rio#contents. >=20 > * Added aliases for the copy operators. (suggested by Dave Burt) > * copy_to > > * append_to >> > * copy_from < > * append_from << >=20 > * Bug fixes and corrections >=20 > Project:: http://rubyforge.org/projects/rio/ > Documentation:: http://rio.rubyforge.org/ > Bugs:: http://rubyforge.org/tracker/?group_id=3D821 > Email:: rio4ruby@rubyforge.org >=20 > =3D=3D Copyright > Copyright (c) 2005, Christopher Kleckner. All rights reserved >=20 > =3D=3D License > Rio is released under the GNU General Public License > (http://www.gnu.org/licenses/gpl.html) >=20 > -Christopher Kleckner >=20 >=20 > ------=_Part_13052_20355439.1126151221993--