lib/rio/if/grande.rb in rio-0.3.3 vs lib/rio/if/grande.rb in rio-0.3.4

- old
+ new

@@ -75,20 +75,22 @@ # * ario.records(*args).to_a # # What constitutes an array element is determined by Rio#lines, Rio#bytes, # or by an extension such as Rio#csv. Rio#lines is the default. # - # Arguments may consist of zero or more integers, ranges, regular expressions, symbols - # and procs. + # Arguments may consist of zero or more integers, ranges, regular expressions, symbols, + # procs, and arrays # An empty argument list selects all records # # 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 + # 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, # When only record ranges are used to select records, @@ -184,11 +186,11 @@ # rio('adir').all['*.txt'] # array of all .txt entries in 'adir and its subdirectories # # rio('adir').files['*.txt'] # array of all .txt files # # rio('adir').dirs['CSV'] # array of all CSV directories - # rio('adir').nodirs['CSV'] # array of all non-CSV directories + # rio('adir').skipdirs['CSV'] # array of all non-CSV directories # def [](*selectors) target[*selectors] end @@ -375,19 +377,19 @@ # # rio('afile').lines(0..9) > ary # ary will contain only the first ten lines of the file # rio('afile').chomp.lines(0..9) > ary # same thing with lines chomped # rio('afile').gzip.chomp.lines(0..9) > ary # same thing from a gzipped file # - # rio('afile').nolines(0..9) > ary # ary will contain all but the first ten lines of the file + # rio('afile').skiplines(0..9) > ary # ary will contain all but the first ten lines of the file # # rio('adir') > ary # ary will contain a Rio for each entry in the directory # rio('adir').files > ary # same, but only files # rio('adir').files('*.rb') >ary # same, but only .rb files # # Copying to a string # rio('afile') > astring # slurp the entire contents of the file into astring - # astring = rio('afile').slurp # same effect + # astring = rio('afile').contents # same effect # # Copy the first line *and* every line containing the word Rio into a gzipped file # rio('src').lines(1,/Rio/) > rio('dst.gz').gzip # # Copy lines of a web page into an array with each line chomped @@ -398,11 +400,11 @@ # 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 # Alias for Rio#> (copy-to grande operator) - def copy(destination) target.copy(destination); self end + def copy_to(destination) target.copy_to(destination); self end # Grande Append-To Operator # # The append-to grande-operator is the same as Rio#> (copy-to) except that it opens the destination # for append. @@ -422,10 +424,14 @@ # 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 def >>(destination) target >> destination; self end + # Alias for Rio#>> (append-to grande operator) + def append_to(destination) target.append_to(destination); self end + + # Grande Append-From Operator # # The append-from grande-operator copies a Rio from another Rio or another ruby object. This # behaves like Rio#< (copy-from) except unopened Rios are opened for append. # @@ -436,10 +442,15 @@ # Rio:: The source Rio is appended using its Rio#>> (append-to) operator # # See Rio#< (copy-from) def <<(source) target << source; self end + + # Alias for Rio#<< (append-from grande operator) + def append_from(source) target.append_from(source); self end + + # Grande Copy-From Operator # # The copy-from grande-operator copies a Rio from another Rio or another ruby object. # Its operation is dependent on the the file system objects referenced, the rio # options set, and the state of its source and destination. In the broadest of terms @@ -519,10 +530,14 @@ # # See also Rio#> (copy-to), Rio#each, Rio#[] # def <(source) target < source; self end + # Alias for Rio#< (copy-from grande operator) + def copy_from(source) target.copy_from(source); self end + + # Reads and returns the next record from a Rio, honoring the grande selection methods. # # Returns nil on end of file. # # See also Rio#records, Rio#lines, Rio#each, Rio#[] @@ -532,7 +547,41 @@ # line11 = ario.getrec # line12 = ario.getrec # a_nil = ario.getrec def getrec() target.getrec() end + # Grande Exclude method + # + # +skip+ can be used in two ways. + # + # If called with no arguments it reverses the polarity of the + # next non-skip grande selection method that is called. That is, + # it turns +lines+, +records+, +rows+, +files+, +dirs+ and +entries+ + # into +skiplines+, +skiprecords+, +skiprows+, +skipfiles+, + # +skipdirs+, and +skipentries+, respectively. + # + # rio('afile').skip.lines(0..5) # same as rio('afile').skiplines(0..5) + # rio('adir').skip.files('*~') # same as rio('adir').skipfiles('*~') + # + # Note that it only affects the next selection method seen -- and may be + # used more than once. If no grande selection method is seen, +skip+ is + # ignored. + # + # When called with arguments it acts like Rio#skipentries for directory + # Rios and like Rio#skiprecords for stream Rios. + # + # rio('afile').lines(/Rio/).skip[0..4] # lines containg 'Rio' excluding the + # # first five lines + # + # rio('adir').files('*.rb').skip[:symlink?] # .rb files, but not symlinks to + # # .rb files + # + # If a block is given, behaves as if <tt>skip(*args).each(&block)</tt> had been called. + # + # Returns the Rio. + # + # See Rio#skiplines, Rio#skiprecords, Rio#skiprows, Rio#skipfiles, + # Rio#skipdirs, and Rio#skipentries. + # + def skip(*args,&block) target.skip(*args,&block); self end end end