rio 0.3.3 → 0.3.4
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +225 -0
- data/README +12 -0
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/doc/ANNOUNCE +160 -71
- data/doc/RELEASE_NOTES +71 -2
- data/ex/colx.rb +1 -1
- data/ex/passwd_report.rb +4 -8
- data/ex/riocat +5 -5
- data/ex/riogunzip +1 -1
- data/ex/riogzip +6 -6
- data/ex/rioprompt.rb +6 -0
- data/lib/rio.rb +3 -13
- data/lib/rio/arycopy.rb +1 -1
- data/lib/rio/base.rb +1 -5
- data/lib/rio/construct.rb +75 -0
- data/lib/rio/constructor.rb +42 -11
- data/lib/rio/context.rb +1 -1
- data/lib/rio/context/dir.rb +50 -23
- data/lib/rio/context/methods.rb +5 -3
- data/lib/rio/{cxdir.rb → context/skip.rb} +24 -36
- data/lib/rio/context/stream.rb +38 -16
- data/lib/rio/cp.rb +24 -5
- data/lib/rio/dir.rb +8 -7
- data/lib/rio/doc/HOWTO.rb +33 -33
- data/lib/rio/doc/INTRO.rb +416 -256
- data/lib/rio/doc/MISC.rb +3 -1
- data/lib/rio/doc/SYNOPSIS.rb +28 -33
- data/lib/rio/entrysel.rb +76 -9
- data/lib/rio/file.rb +2 -1
- data/lib/rio/filter.rb +95 -0
- data/lib/rio/filter/closeoneof.rb +1 -1
- data/lib/rio/grande.rb +0 -74
- data/lib/rio/if.rb +2 -1
- data/lib/rio/if/basic.rb +1 -1
- data/lib/rio/if/csv.rb +1 -1
- data/lib/rio/if/dir.rb +1 -220
- data/lib/rio/if/fileordir.rb +26 -12
- data/lib/rio/if/grande.rb +55 -6
- data/lib/rio/if/grande_entry.rb +355 -0
- data/lib/rio/if/{methods.rb → grande_stream.rb} +69 -88
- data/lib/rio/if/path.rb +25 -3
- data/lib/rio/if/stream.rb +62 -37
- data/lib/rio/if/temp.rb +2 -2
- data/lib/rio/if/test.rb +23 -0
- data/lib/rio/impl/path.rb +5 -0
- data/lib/rio/match.rb +6 -3
- data/lib/rio/matchrecord.rb +50 -46
- data/lib/rio/{filter/chomp.rb → ops/construct.rb} +12 -20
- data/lib/rio/ops/create.rb +3 -0
- data/lib/rio/ops/dir.rb +12 -6
- data/lib/rio/ops/either.rb +17 -3
- data/lib/rio/ops/path.rb +4 -1
- data/lib/rio/ops/stream/input.rb +6 -1
- data/lib/rio/ops/stream/read.rb +1 -3
- data/lib/rio/{context/chomp.rb → prompt.rb} +17 -13
- data/lib/rio/rl/base.rb +1 -1
- data/lib/rio/rl/builder.rb +3 -1
- data/lib/rio/state.rb +7 -13
- data/lib/rio/stream.rb +8 -5
- data/lib/rio/stream/open.rb +1 -1
- data/lib/rio/version.rb +1 -1
- data/test/mswin32.rb +1 -1
- data/test/runtests_gem.rb +1 -1
- data/test/tc/all.rb +3 -0
- data/test/tc/copy-from.rb +13 -13
- data/test/tc/copy-to.rb +1 -1
- data/test/tc/copy.rb +1 -1
- data/test/tc/copydir.rb +0 -24
- data/test/tc/copysymlink.rb +39 -0
- data/test/tc/csv.rb +2 -2
- data/test/tc/csv2.rb +4 -4
- data/test/tc/misc.rb +16 -16
- data/test/tc/nolines.rb +26 -26
- data/test/tc/noqae.rb +74 -74
- data/test/tc/overload.rb +28 -28
- data/test/tc/riorl.rb +36 -0
- data/test/tc/selnosel.rb +36 -0
- data/test/tc/skip.rb +58 -0
- data/test/tc/skiplines.rb +42 -0
- data/test/tc/symlink.rb +1 -1
- data/test/tc/symlink0.rb +1 -1
- data/test/tc/temp.rb +1 -1
- data/test/tc/tempdir.rb +1 -1
- data/test/tc/testcase.rb +7 -1
- metadata +14 -8
- data/lib/rio/matchcolumns.rb +0 -266
- data/lib/rio/rangemath.rb +0 -44
data/lib/rio/if.rb
CHANGED
data/lib/rio/if/basic.rb
CHANGED
@@ -57,7 +57,7 @@ module RIO
|
|
57
57
|
# Returns true if their String representations are eql?
|
58
58
|
def eql?(other) target.eql?(other) end
|
59
59
|
|
60
|
-
# Match - invokes other.=~, passing the value returned by Rio#
|
60
|
+
# Match - invokes other.=~, passing the value returned by Rio#to_str
|
61
61
|
def =~(other) target =~ other end
|
62
62
|
|
63
63
|
end
|
data/lib/rio/if/csv.rb
CHANGED
@@ -60,7 +60,7 @@ module RIO
|
|
60
60
|
# rio("afile.csv").csv.nocolumns(2,3..5) { |array_of_fields| ... }
|
61
61
|
#
|
62
62
|
# # an array containg all but the first line returning columns 5,6 and 7
|
63
|
-
# rio("afile.csv").csv.columns(5..7).
|
63
|
+
# rio("afile.csv").csv.columns(5..7).skiplines[0]
|
64
64
|
#
|
65
65
|
# See RIO::Doc::INTRO for complete documentation on csv mode.
|
66
66
|
def csv(field_separator=',',record_separator=nil,&block)
|
data/lib/rio/if/dir.rb
CHANGED
@@ -59,225 +59,6 @@ module RIO
|
|
59
59
|
|
60
60
|
|
61
61
|
|
62
|
-
# Grande Directory Selection Method
|
63
|
-
#
|
64
|
-
# Sets the rio to return directories. _args_ can be used to select which directories are returned.
|
65
|
-
# ario.files(*args) do |f|
|
66
|
-
# f.directory? #=> true
|
67
|
-
# end
|
68
|
-
# No aguments selects all directories.
|
69
|
-
# if _args_ are:
|
70
|
-
# Regexp:: selects matching directories
|
71
|
-
# glob:: selects matching directories
|
72
|
-
# Proc:: called for each directory. the directory is processed unless the proc returns false
|
73
|
-
# Symbol:: sent to each directory. Each directory is processed unless the symbol returns false
|
74
|
-
#
|
75
|
-
# If a block is given, behaves like <tt>ario.dirs(*args).each(&block)</tt>
|
76
|
-
#
|
77
|
-
# See also Rio#files, Rio#entries, Rio#nodirs
|
78
|
-
#
|
79
|
-
# rio('adir').dirs { |frio| ... } # process all directories in 'adir'
|
80
|
-
# rio('adir').all.dirs { |frio| ... } # same thing recursively
|
81
|
-
# rio('adir').dirs(/^\./) { |frio| ...} # process dot directories
|
82
|
-
# rio('adir').dirs[/^\./] # return an array of dot directories
|
83
|
-
# rio('adir').dirs[:symlink?] # an array of symlinks to directories
|
84
|
-
#
|
85
|
-
def dirs(*args,&block) target.dirs(*args,&block); self end
|
86
|
-
|
87
|
-
# Grande Directory Exclude Method
|
88
|
-
#
|
89
|
-
# If no args are provided selects anything but directories.
|
90
|
-
# ario.nodirs do |el|
|
91
|
-
# el.directory? #=> false
|
92
|
-
# end
|
93
|
-
# If args are provided, sets the rio to select directories as with Rio#dirs, but the arguments are
|
94
|
-
# used to determine which directories will *not* be processed
|
95
|
-
#
|
96
|
-
# If a block is given behaves like
|
97
|
-
# ario.nodirs(*args).each(&block)
|
98
|
-
#
|
99
|
-
# See Rio#dirs
|
100
|
-
#
|
101
|
-
# rio('adir').nodirs { |ent| ... } # iterate through everything except directories
|
102
|
-
# rio('adir').nodirs(/^\./) { |drio| ... } # iterate through directories, skipping dot directories
|
103
|
-
#
|
104
|
-
#
|
105
|
-
def nodirs(*args,&block) target.nodirs(*args,&block); self end
|
106
|
-
|
107
|
-
|
108
|
-
# Grande Directory Entry Selection Method
|
109
|
-
#
|
110
|
-
# No aguments selects all entries.
|
111
|
-
#
|
112
|
-
# if +args+ are:
|
113
|
-
# Regexp:: selects matching entries
|
114
|
-
# glob:: selects matching entries
|
115
|
-
# Proc:: called for each entry. the entry is processed unless the proc returns false
|
116
|
-
# Symbol:: sent to each entry. Each entry is processed unless the symbol returns false
|
117
|
-
#
|
118
|
-
# If a block is given, behaves like <tt>ario.etries(*args).each(&block)</tt>
|
119
|
-
#
|
120
|
-
# See also Rio#files, Rio#dirs, Rio#noentries
|
121
|
-
#
|
122
|
-
# rio('adir').entries { |frio| ... } # process all entries in 'adir'
|
123
|
-
# rio('adir').all.entries { |frio| ... } # same thing recursively
|
124
|
-
# rio('adir').entries(/^\./) { |frio| ...} # process entries starting with a dot
|
125
|
-
# rio('adir').entries[/^\./] # return an array of all entries starting with a dot
|
126
|
-
# rio('adir').entries[:symlink?] # an array of symlinks in 'adir'
|
127
|
-
#
|
128
|
-
def entries(*args,&block) target.entries(*args,&block); self end
|
129
|
-
|
130
|
-
# Grande Directory Entry Rejection Method
|
131
|
-
#
|
132
|
-
# No aguments rejects all entries.
|
133
|
-
#
|
134
|
-
# Behaves like Rio#entries, except that matching entries are excluded.
|
135
|
-
#
|
136
|
-
def noentries(*args,&block) target.noentries(*args,&block); self end
|
137
|
-
|
138
|
-
|
139
|
-
# Grande File Selection Method
|
140
|
-
#
|
141
|
-
# Sets the rio to return files. +args+ can be used to select which files are returned.
|
142
|
-
# ario.files(*args) do |f|
|
143
|
-
# f.file? #=> true
|
144
|
-
# end
|
145
|
-
# No aguments selects all files.
|
146
|
-
#
|
147
|
-
# +args+ may be one or more of the following:
|
148
|
-
# Regexp:: selects matching files
|
149
|
-
# String:: treated as a glob, and selects matching files
|
150
|
-
# Proc:: called for each file. the file is processed unless the proc returns false
|
151
|
-
# Symbol:: sent to each file. Each file is processed unless the symbol returns false
|
152
|
-
#
|
153
|
-
# If a block is given, behaves like <tt>ario.files(*args).each</tt>
|
154
|
-
#
|
155
|
-
# See also Rio#dirs, Rio#entries, Rio#nofiles
|
156
|
-
#
|
157
|
-
# rio('adir').files { |frio| ... } # process all files in 'adir'
|
158
|
-
# rio('adir').all.files { |frio| ... } # same thing recursively
|
159
|
-
# rio('adir').files('*.rb') { |frio| ...} # process .rb files
|
160
|
-
# rio('adir').files['*.rb'] # return an array of .rb files
|
161
|
-
# rio('adir').files[/\.rb$/] # same thing using a regular expression
|
162
|
-
# rio('adir').files[:symlink?] # an array of symlinks to files
|
163
|
-
#
|
164
|
-
# For Rios that refer to files, <tt>files(*args)</tt> causes the file to be processed only if
|
165
|
-
# it meets the criteria specified by the args.
|
166
|
-
#
|
167
|
-
# rio('afile.z').files['*.z'] #=> [rio('afile.z')]
|
168
|
-
# rio('afile.q').files['*.z'] #=> []
|
169
|
-
#
|
170
|
-
# Example
|
171
|
-
#
|
172
|
-
# Problem:
|
173
|
-
#
|
174
|
-
# Need an array of all ruby programs in a directory and its subdirectories, skipping those in _subversion_ (.svn)
|
175
|
-
# directories. For the purposes of this problem, a Ruby program is defined as a file ending with .rb or a file
|
176
|
-
# that is executable and whose shebang line contains 'ruby'
|
177
|
-
#
|
178
|
-
# rio(path).norecurse('.svn').files['*.rb',proc{ |f| f.executable? and f.gets =~ /^#!.+ruby/ }]
|
179
|
-
#
|
180
|
-
# Explanation:
|
181
|
-
#
|
182
|
-
# Create a Rio for a directory
|
183
|
-
# rio(path)
|
184
|
-
# Specify that '.svn' directories should not be included in recursion.
|
185
|
-
# rio(path).norecurse('.svn')
|
186
|
-
# Select files
|
187
|
-
# rio(path).norecurse('.svn').files
|
188
|
-
# Limit to files ending with '.rb'
|
189
|
-
# rio(path).norecurse('.svn').files('*.rb')
|
190
|
-
# Also allow files that are both executable and whose first line is a shebang-ruby line
|
191
|
-
# rio(path).norecurse('.svn').files('*.rb',proc{ |f| f.executable? and f.gets =~ /^#!.+ruby/ })
|
192
|
-
# Return an array rather than iterating thru them
|
193
|
-
# rio(path).norecurse('.svn').files['*.rb',proc{ |f| f.executable? and f.gets =~ /^#!.+ruby/ }]
|
194
|
-
#
|
195
|
-
def files(*args,&block) target.files(*args,&block); self end
|
196
|
-
|
197
|
-
# Grande File Exclude Method
|
198
|
-
#
|
199
|
-
# If no args are provided selects anything but files.
|
200
|
-
# ario.nofiles do |el|
|
201
|
-
# el.file? #=> false
|
202
|
-
# end
|
203
|
-
# If args are provided, sets the rio to select files as with Rio#files, but the arguments are
|
204
|
-
# used to determine which files will *not* be processed
|
205
|
-
#
|
206
|
-
# If a block is given behaves like <tt>ario.nofiles(*args).each(&block)</tt>
|
207
|
-
#
|
208
|
-
# See Rio#files
|
209
|
-
#
|
210
|
-
# rio('adir').nofiles { |ent| ... } # iterate through everything except files
|
211
|
-
# rio('adir').nofiles(*~) { |frio| ... } # iterate through files, skipping those ending with a tilde
|
212
|
-
#
|
213
|
-
#
|
214
|
-
def nofiles(*args,&block) target.nofiles(*args,&block); self end
|
215
|
-
|
216
|
-
|
217
|
-
# Returns +true+ if the rio is in +all+ (recursive) mode. See Rio#all
|
218
|
-
#
|
219
|
-
# adir = rio('adir').all.dirs
|
220
|
-
# adir.all? # true
|
221
|
-
# adir.each do |subdir|
|
222
|
-
# subdir.all? # true
|
223
|
-
# end
|
224
|
-
#
|
225
|
-
# rio('adir').all? # false
|
226
|
-
#
|
227
|
-
def all?() target.all?() end
|
228
|
-
|
229
|
-
|
230
|
-
# Grande Directory Recursion Method
|
231
|
-
#
|
232
|
-
# Sets the Rio to all mode (recursive)
|
233
|
-
#
|
234
|
-
# When called with a block, behaves as if all.each(&block) had been called
|
235
|
-
#
|
236
|
-
# +all+ causes subsequent calls to +files+ or +dirs+ to be applied recursively
|
237
|
-
# to subdirectories
|
238
|
-
#
|
239
|
-
# rio('adir').all.files('*.[ch]').each { |file| ... } # process all c language source files in adir
|
240
|
-
# # and all subdirectories of adir
|
241
|
-
# rio('adir').all.files(/\.[ch]$/) { |file| ... } # same as above
|
242
|
-
# rio('adir').files("*.[ch]").all { |file| ... } # once again
|
243
|
-
# rio('adir').all.files["*.[ch]"] # same, but return an array instead of iterating
|
244
|
-
#
|
245
|
-
def all(arg=true,&block) target.all(arg,&block); self end
|
246
|
-
|
247
|
-
|
248
|
-
# Grande Directory Recursion Selection Method
|
249
|
-
#
|
250
|
-
# Sets the Rio to recurse into directories like Rio#all. If no args are provided behaves like Rio#all.
|
251
|
-
# If args are provided, they are processed like Rio#dirs, to select which subdirectories should
|
252
|
-
# be recursed into. Rio#recurse always implies Rio#all.
|
253
|
-
#
|
254
|
-
# +args+ may be one or more of:
|
255
|
-
# Regexp:: recurse into matching subdirectories
|
256
|
-
# glob:: recurse into matching subdirectories
|
257
|
-
# Proc:: called for each directory. The directory is recursed into unless the proc returns false
|
258
|
-
# Symbol:: sent to each directory. Each directory is recursed into unless the symbol returns false
|
259
|
-
#
|
260
|
-
# If a block is given, behaves like <tt>ario.recurse(*args).each(&block)</tt>
|
261
|
-
#
|
262
|
-
# See also Rio#norecurse, Rio#all, Rio#dirs
|
263
|
-
#
|
264
|
-
# rio('adir').all.recurse('test*') { |drio| ... } # process all entries and all entries in subdirectories
|
265
|
-
# # starting with 'test' -- recursively
|
266
|
-
#
|
267
|
-
def recurse(*args,&block) target.recurse(*args,&block); self end
|
268
|
-
|
269
|
-
|
270
|
-
# Grande Directory Recursion Exclude Method
|
271
|
-
#
|
272
|
-
# Sets the Rio to recurse into directories like Rio#all. If no args are provided, no
|
273
|
-
# directories will be recursed into. If args are provided, behaves like Rio#recurse, except
|
274
|
-
# that mathcing will *not* be recursed into
|
275
|
-
#
|
276
|
-
# rio('adir').norecurse('.svn') { |drio| ... } # recurse, skipping subversion directories
|
277
|
-
#
|
278
|
-
def norecurse(*args,&block) target.norecurse(*args,&block); self end
|
279
|
-
|
280
|
-
|
281
62
|
# Calls Find#find
|
282
63
|
#
|
283
64
|
# Uses Find#find to find all entries recursively for a Rio that
|
@@ -329,7 +110,7 @@ module RIO
|
|
329
110
|
# Removes a directory Rio recursively. Returns the Rio.
|
330
111
|
# If the directory does not exist, simply returns the Rio
|
331
112
|
#
|
332
|
-
# If called with a block, behaves as if rmtree.each(&block) had been called
|
113
|
+
# If called with a block, behaves as if <tt>rmtree.each(&block)</tt> had been called
|
333
114
|
#
|
334
115
|
# See also Rio#delete!
|
335
116
|
#
|
data/lib/rio/if/fileordir.rb
CHANGED
@@ -38,15 +38,28 @@
|
|
38
38
|
module RIO
|
39
39
|
class Rio
|
40
40
|
|
41
|
+
# undocumented
|
42
|
+
def open(m,*args,&block) target.open(m,*args,&block); self end
|
43
|
+
# if block_given?
|
44
|
+
# old_closeoncopy,old_closeoneof = closeoncopy?,closeoneof?
|
45
|
+
# begin
|
46
|
+
# return yield(nocloseoncopy.nocloseoneof)
|
47
|
+
# ensure
|
48
|
+
# reset.closeoncopy(old_closeoncopy).closeoneof(old_closeoneof)
|
49
|
+
# end
|
50
|
+
# end
|
51
|
+
# self
|
52
|
+
# end
|
53
|
+
|
41
54
|
# Creates a symbolic link _dest_ which points to the Rio's Rio#fspath.
|
42
55
|
# Raises a NotImplementedError exception on platforms that do not support symbolic links.
|
43
56
|
# _dest_ may be a Rio, a String, or anything that will create an appropriate Rio
|
44
|
-
# when passed to Rio#new
|
57
|
+
# when passed to Rio#new .
|
45
58
|
# If _dest_ already exists and is a directory, creates a symbolic link in the _dest_ directory,
|
46
|
-
# named with the name returned by Rio#filename
|
59
|
+
# named with the name returned by Rio#filename.
|
47
60
|
# If _dest_ already exists and it is not a directory, raises Errno::EEXIST.
|
48
61
|
#
|
49
|
-
# Returns the Rio (not the symlink)
|
62
|
+
# Returns the Rio (not the symlink).
|
50
63
|
#
|
51
64
|
# Rio#symlink differs from File#symlink when the Rio or the _dest_ path has directory information.
|
52
65
|
# In this case Rio#symlink creates a symlink that actually refers to the Rio's location
|
@@ -78,17 +91,18 @@ module RIO
|
|
78
91
|
#
|
79
92
|
def readlink(*args) target.readlink(*args) end
|
80
93
|
|
81
|
-
# If called with an argument calls FileUtils#rename
|
82
|
-
# If called without an argument puts the Rio in
|
83
|
-
# which changes to the Rio's path affect a rename of the file
|
84
|
-
# on the file system.
|
85
|
-
#
|
94
|
+
# If called with an argument calls FileUtils#rename.
|
95
|
+
# If called without an argument puts the Rio in "rename mode".
|
86
96
|
# Proxy for FileUtils#rename
|
87
97
|
# ario = rio('afile.cpp')
|
88
98
|
# ario.rename('afile.cxx') # renamed the file, but ario still references
|
89
99
|
# # the old path
|
90
100
|
# Rename Mode
|
91
101
|
#
|
102
|
+
# In rename mode changes to a Rio's path with Rio#dirname=, Rio#filename=,
|
103
|
+
# Rio#basename=, and Rio#extname= also cause the object on the filesystem
|
104
|
+
# to be renamed.
|
105
|
+
#
|
92
106
|
# Change the extension of all'.cpp' files in 'adir' to '.cxx'
|
93
107
|
# rio('adir').rename.files('*.cpp') do |file|
|
94
108
|
# file.ext = '.cxx' # 'file' references the new path and the actual file is renamed
|
@@ -168,12 +182,12 @@ module RIO
|
|
168
182
|
# Seeks to a given offset _amount_ in the stream according to the
|
169
183
|
# value of _whence_:
|
170
184
|
#
|
171
|
-
# IO::SEEK_CUR | Seeks to
|
185
|
+
# IO::SEEK_CUR | Seeks to 'amount' plus current position
|
172
186
|
# --------------+----------------------------------------------------
|
173
|
-
# IO::SEEK_END | Seeks to
|
174
|
-
# | want a negative value for
|
187
|
+
# IO::SEEK_END | Seeks to 'amount' plus end of stream (you probably
|
188
|
+
# | want a negative value for 'amount')
|
175
189
|
# --------------+----------------------------------------------------
|
176
|
-
# IO::SEEK_SET | Seeks to the absolute location given by
|
190
|
+
# IO::SEEK_SET | Seeks to the absolute location given by 'amount'
|
177
191
|
#
|
178
192
|
# Example:
|
179
193
|
#
|
data/lib/rio/if/grande.rb
CHANGED
@@ -77,8 +77,8 @@ module RIO
|
|
77
77
|
# What constitutes an array element is determined by Rio#lines, Rio#bytes,
|
78
78
|
# or by an extension such as Rio#csv. Rio#lines is the default.
|
79
79
|
#
|
80
|
-
# Arguments may consist of zero or more integers, ranges, regular expressions, symbols
|
81
|
-
# and
|
80
|
+
# Arguments may consist of zero or more integers, ranges, regular expressions, symbols,
|
81
|
+
# procs, and arrays
|
82
82
|
# An empty argument list selects all records
|
83
83
|
#
|
84
84
|
# Records are selected as follows.
|
@@ -87,6 +87,8 @@ module RIO
|
|
87
87
|
# integer:: treated like a one element range
|
88
88
|
# symbol:: the symbol is sent to the string. record is selected unless false is returned
|
89
89
|
# proc:: the proc is called with the string as an argument. record is selected unless false is returned
|
90
|
+
# array:: the array may contain any of the other selector types. record is selected
|
91
|
+
# unless any of the selectors returns false. (a logical and)
|
90
92
|
#
|
91
93
|
# A record matching *any* of the selectors will be included in the array. (acts like an _or_)
|
92
94
|
#
|
@@ -186,7 +188,7 @@ module RIO
|
|
186
188
|
# rio('adir').files['*.txt'] # array of all .txt files
|
187
189
|
#
|
188
190
|
# rio('adir').dirs['CSV'] # array of all CSV directories
|
189
|
-
# rio('adir').
|
191
|
+
# rio('adir').skipdirs['CSV'] # array of all non-CSV directories
|
190
192
|
#
|
191
193
|
def [](*selectors) target[*selectors] end
|
192
194
|
|
@@ -377,7 +379,7 @@ module RIO
|
|
377
379
|
# rio('afile').chomp.lines(0..9) > ary # same thing with lines chomped
|
378
380
|
# rio('afile').gzip.chomp.lines(0..9) > ary # same thing from a gzipped file
|
379
381
|
#
|
380
|
-
# rio('afile').
|
382
|
+
# rio('afile').skiplines(0..9) > ary # ary will contain all but the first ten lines of the file
|
381
383
|
#
|
382
384
|
# rio('adir') > ary # ary will contain a Rio for each entry in the directory
|
383
385
|
# rio('adir').files > ary # same, but only files
|
@@ -385,7 +387,7 @@ module RIO
|
|
385
387
|
#
|
386
388
|
# Copying to a string
|
387
389
|
# rio('afile') > astring # slurp the entire contents of the file into astring
|
388
|
-
# astring = rio('afile').
|
390
|
+
# astring = rio('afile').contents # same effect
|
389
391
|
#
|
390
392
|
# Copy the first line *and* every line containing the word Rio into a gzipped file
|
391
393
|
# rio('src').lines(1,/Rio/) > rio('dst.gz').gzip
|
@@ -400,7 +402,7 @@ module RIO
|
|
400
402
|
def >(destination) target > destination; self end
|
401
403
|
|
402
404
|
# Alias for Rio#> (copy-to grande operator)
|
403
|
-
def
|
405
|
+
def copy_to(destination) target.copy_to(destination); self end
|
404
406
|
|
405
407
|
# Grande Append-To Operator
|
406
408
|
#
|
@@ -424,6 +426,10 @@ module RIO
|
|
424
426
|
def >>(destination) target >> destination; self end
|
425
427
|
|
426
428
|
|
429
|
+
# Alias for Rio#>> (append-to grande operator)
|
430
|
+
def append_to(destination) target.append_to(destination); self end
|
431
|
+
|
432
|
+
|
427
433
|
# Grande Append-From Operator
|
428
434
|
#
|
429
435
|
# The append-from grande-operator copies a Rio from another Rio or another ruby object. This
|
@@ -438,6 +444,11 @@ module RIO
|
|
438
444
|
# See Rio#< (copy-from)
|
439
445
|
def <<(source) target << source; self end
|
440
446
|
|
447
|
+
|
448
|
+
# Alias for Rio#<< (append-from grande operator)
|
449
|
+
def append_from(source) target.append_from(source); self end
|
450
|
+
|
451
|
+
|
441
452
|
# Grande Copy-From Operator
|
442
453
|
#
|
443
454
|
# The copy-from grande-operator copies a Rio from another Rio or another ruby object.
|
@@ -521,6 +532,10 @@ module RIO
|
|
521
532
|
#
|
522
533
|
def <(source) target < source; self end
|
523
534
|
|
535
|
+
# Alias for Rio#< (copy-from grande operator)
|
536
|
+
def copy_from(source) target.copy_from(source); self end
|
537
|
+
|
538
|
+
|
524
539
|
# Reads and returns the next record from a Rio, honoring the grande selection methods.
|
525
540
|
#
|
526
541
|
# Returns nil on end of file.
|
@@ -534,5 +549,39 @@ module RIO
|
|
534
549
|
# a_nil = ario.getrec
|
535
550
|
def getrec() target.getrec() end
|
536
551
|
|
552
|
+
# Grande Exclude method
|
553
|
+
#
|
554
|
+
# +skip+ can be used in two ways.
|
555
|
+
#
|
556
|
+
# If called with no arguments it reverses the polarity of the
|
557
|
+
# next non-skip grande selection method that is called. That is,
|
558
|
+
# it turns +lines+, +records+, +rows+, +files+, +dirs+ and +entries+
|
559
|
+
# into +skiplines+, +skiprecords+, +skiprows+, +skipfiles+,
|
560
|
+
# +skipdirs+, and +skipentries+, respectively.
|
561
|
+
#
|
562
|
+
# rio('afile').skip.lines(0..5) # same as rio('afile').skiplines(0..5)
|
563
|
+
# rio('adir').skip.files('*~') # same as rio('adir').skipfiles('*~')
|
564
|
+
#
|
565
|
+
# Note that it only affects the next selection method seen -- and may be
|
566
|
+
# used more than once. If no grande selection method is seen, +skip+ is
|
567
|
+
# ignored.
|
568
|
+
#
|
569
|
+
# When called with arguments it acts like Rio#skipentries for directory
|
570
|
+
# Rios and like Rio#skiprecords for stream Rios.
|
571
|
+
#
|
572
|
+
# rio('afile').lines(/Rio/).skip[0..4] # lines containg 'Rio' excluding the
|
573
|
+
# # first five lines
|
574
|
+
#
|
575
|
+
# rio('adir').files('*.rb').skip[:symlink?] # .rb files, but not symlinks to
|
576
|
+
# # .rb files
|
577
|
+
#
|
578
|
+
# If a block is given, behaves as if <tt>skip(*args).each(&block)</tt> had been called.
|
579
|
+
#
|
580
|
+
# Returns the Rio.
|
581
|
+
#
|
582
|
+
# See Rio#skiplines, Rio#skiprecords, Rio#skiprows, Rio#skipfiles,
|
583
|
+
# Rio#skipdirs, and Rio#skipentries.
|
584
|
+
#
|
585
|
+
def skip(*args,&block) target.skip(*args,&block); self end
|
537
586
|
end
|
538
587
|
end
|