lib/rio/if/grande.rb in rio-0.3.7 vs lib/rio/if/grande.rb in rio-0.3.8

- old
+ new

@@ -1,8 +1,8 @@ #-- # =============================================================================== -# Copyright (c) 2005, Christopher Kleckner +# Copyright (c) 2005, 2006 Christopher Kleckner # All rights reserved # # This file is part of the Rio library for ruby. # # Rio is free software; you can redistribute it and/or modify @@ -20,11 +20,11 @@ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # =============================================================================== #++ # # To create the documentation for Rio run the command -# rake rdoc +# ruby build_doc.rb # from the distribution directory. Then point your browser at the 'doc/rdoc' directory. # # Suggested Reading # * RIO::Doc::SYNOPSIS # * RIO::Doc::INTRO @@ -32,11 +32,11 @@ # * RIO::Rio # # <b>Rio is pre-alpha software. # The documented interface and behavior is subject to change without notice.</b> - +require 'rio/no_warn' module RIO class Rio # module IF # module Grande # Returns the contents of the rio as an array. @@ -85,13 +85,15 @@ # # Records are selected as follows. # range:: specifies a range of records to be selected (zero based) # regexp:: matching records will be selected. # integer:: treated like a one element range - # symbol:: the symbol is sent to the string. record is selected unless false is returned - # proc:: the proc is called with the string as an argument. record is selected unless false is returned - # array:: the array may contain any of the other selector types. record is selected + # symbol:: the symbol is sent to each record. Record is selected + # unless false is returned + # proc:: the proc is called with the record as an argument. + # Record is selected unless false is returned + # array:: the array may contain any of the other selector types. Record is selected # unless any of the selectors returns false. (a logical and) # # A record matching *any* of the selectors will be included in the array. (acts like an _or_) # # Because this is implemented in terms of the Rio#each, @@ -399,11 +401,16 @@ # # Copy the first and 8th through 10th columns of the first ten rows of a gzipped csv # file on a web site into a local gzipped csv file that uses semi-colons as separators # rio('http://domain/file.csv.gz').columns(0,7..9).gzip.csv[0..9] > rio('localfile.csv.gz').csv(';').gzip # - def >(destination) target > destination; self end + def >(destination) + RIO::no_warn { + target > destination; + } + self + end # Alias for Rio#> (copy-to grande operator) def copy_to(destination) target.copy_to(destination); self end @@ -466,12 +473,11 @@ # See Rio#> (copy-to) # # rio('afile') >> rio('anotherfile') # append the contents of 'afile' to 'anotherfile' # rio('afile') >> rio('adir') # copies 'afile' to the directory 'adir' # rio('adir') >> rio('anotherdir') # copy directory 'adir' recursively to 'anotherdir' - # rio('adir') >> array # appendscopy directory 'adir' recursively to 'anotherdir' - # rio('adir') >> ary # a Rio for each entry in the directory will be appended to ary + # rio('adir') >> array # a Rio for each entry in the directory will be appended to ary def >>(destination) target >> destination; self end # Alias for Rio#>> (append-to grande operator) def append_to(destination) target.append_to(destination); self end @@ -575,11 +581,16 @@ # rio('skeldir') < rio('adir').dirs # copy only the directory structure # rio('destdir') < rio('adir').dirs.files(/^\./) # copy the directory structure and all dot files # # See also Rio#> (copy-to), Rio#each, Rio#[] # - def <(source) target < source; self end + def <(source) + RIO::no_warn { + target < source + } + self + end # Alias for Rio#< (copy-from grande operator) def copy_from(source) target.copy_from(source); self end @@ -656,7 +667,18 @@ # # See Rio#skiplines, Rio#skiprecords, Rio#skiprows, Rio#skipfiles, # Rio#skipdirs, and Rio#skipentries. # def skip(*args,&block) target.skip(*args,&block); self end + + + # Returns true if the referenced file or directory is empty after honoring the grande + # selection methods. + # + # rio('f0').delete!.touch.empty? #=> true + # rio('f1').puts!("Not Empty\n").empty? #=> false + # rio('d0').delete!.mkdir.empty? #=> true + # + def empty?() target.empty? end + end end