rio 0.3.3 → 0.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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/context.rb
CHANGED
data/lib/rio/context/dir.rb
CHANGED
@@ -42,24 +42,66 @@ require 'rio/entrysel'
|
|
42
42
|
module RIO
|
43
43
|
module Cx
|
44
44
|
module Methods
|
45
|
-
def dir_iter?() cx.has_key?('
|
45
|
+
def dir_iter?() cx.has_key?('entry_sel') end
|
46
46
|
|
47
47
|
private
|
48
48
|
|
49
|
-
def
|
50
|
-
|
51
|
-
cx[key] << Match::Entry::List.new(sym,*args)
|
52
|
-
self
|
53
|
-
end
|
49
|
+
def _set_entry_sel_args(sel_type,*args)
|
50
|
+
#p callstr('_set_entry_sel_args',sel_type,*args)
|
54
51
|
|
52
|
+
es = (cx['entry_sel'] ||= {})
|
53
|
+
eargs = (es['args'] ||= {})
|
54
|
+
eargs[sel_type] ||= []
|
55
|
+
eargs[sel_type] += args
|
56
|
+
end
|
55
57
|
|
56
|
-
def _set_select(ss_type
|
58
|
+
def _set_select(ss_type,*args,&block)
|
57
59
|
cx['ss_type'] = ss_type
|
58
|
-
|
60
|
+
_set_entry_sel_args(ss_type,*args)
|
59
61
|
return each(&block) if block_given?
|
60
62
|
self
|
61
63
|
end
|
62
64
|
|
65
|
+
def _selkey(sel_type)
|
66
|
+
#p callstr('_selkey',sel_type,skipping?)
|
67
|
+
if skipping?
|
68
|
+
cx['skipping'] = false
|
69
|
+
'skip' + sel_type
|
70
|
+
else
|
71
|
+
sel_type
|
72
|
+
end
|
73
|
+
end
|
74
|
+
public
|
75
|
+
|
76
|
+
def entries(*args,&block)
|
77
|
+
_set_select(_selkey('entries'),*args,&block)
|
78
|
+
end
|
79
|
+
def files(*args,&block)
|
80
|
+
_set_select(_selkey('files'),*args,&block)
|
81
|
+
end
|
82
|
+
def dirs(*args,&block)
|
83
|
+
_set_select(_selkey('dirs'),*args,&block)
|
84
|
+
end
|
85
|
+
|
86
|
+
def skipentries(*args,&block)
|
87
|
+
_set_select('skipentries',*args,&block)
|
88
|
+
end
|
89
|
+
def skipfiles(*args,&block)
|
90
|
+
_set_select('skipfiles',*args,&block)
|
91
|
+
end
|
92
|
+
def skipdirs(*args,&block)
|
93
|
+
_set_select('skipdirs',*args,&block)
|
94
|
+
end
|
95
|
+
|
96
|
+
private
|
97
|
+
|
98
|
+
def _addselkey(key,sym,*args)
|
99
|
+
#p callstr('_addselkey',key,sym,*args)
|
100
|
+
cx[key] ||= Match::Entry::Sels.new
|
101
|
+
cx[key] << Match::Entry::List.new(sym,*args)
|
102
|
+
self
|
103
|
+
end
|
104
|
+
|
63
105
|
public
|
64
106
|
|
65
107
|
def recurse(*args,&block)
|
@@ -72,21 +114,6 @@ module RIO
|
|
72
114
|
return each(&block) if block_given?
|
73
115
|
self
|
74
116
|
end
|
75
|
-
def entries(*args,&block) _set_select('entries','sel',:true?,*args,&block) end
|
76
|
-
def files(*args,&block) _set_select('files','sel',:file?,*args,&block) end
|
77
|
-
def dirs(*args,&block) _set_select('dirs','sel',:dir?,*args,&block) end
|
78
|
-
|
79
|
-
def noentries(*args,&block)
|
80
|
-
_set_select('noentries','nosel',:true?,*args,&block)
|
81
|
-
end
|
82
|
-
def nofiles(*args,&block)
|
83
|
-
_addselkey('sel',:file?) unless args.empty?
|
84
|
-
_set_select('nofiles','nosel',:file?,*args,&block)
|
85
|
-
end
|
86
|
-
def nodirs(*args,&block)
|
87
|
-
_addselkey('sel',:dir?) unless args.empty?
|
88
|
-
_set_select('nodirs','nosel',:dir?,*args,&block)
|
89
|
-
end
|
90
117
|
end
|
91
118
|
end
|
92
119
|
end
|
data/lib/rio/context/methods.rb
CHANGED
@@ -40,19 +40,21 @@ require 'rio/iomode'
|
|
40
40
|
|
41
41
|
require 'rio/context/stream'
|
42
42
|
require 'rio/context/dir'
|
43
|
-
require 'rio/context/
|
43
|
+
require 'rio/context/skip'
|
44
|
+
require 'rio/filter'
|
44
45
|
require 'rio/context/closeoneof'
|
45
46
|
require 'rio/context/gzip'
|
46
47
|
|
47
48
|
module RIO
|
48
49
|
module Cx #:nodoc: all
|
49
50
|
module SS
|
50
|
-
STREAM_KEYS = %w[records lines rows bytes
|
51
|
-
ENTRY_KEYS = %w[entries files dirs
|
51
|
+
STREAM_KEYS = %w[records lines rows bytes skiplines skiprows skiprecords nobytes]
|
52
|
+
ENTRY_KEYS = %w[entries files dirs skipfiles skipdirs skipentries]
|
52
53
|
KEYS = ENTRY_KEYS + STREAM_KEYS
|
53
54
|
end
|
54
55
|
end
|
55
56
|
end
|
57
|
+
|
56
58
|
module RIO
|
57
59
|
module Cx
|
58
60
|
module Methods
|
@@ -35,45 +35,33 @@
|
|
35
35
|
# The documented interface and behavior is subject to change without notice.</b>
|
36
36
|
|
37
37
|
|
38
|
+
require 'rio/context/cxx.rb'
|
39
|
+
|
38
40
|
module RIO
|
39
|
-
module
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
cx.keys.reject { |k| CX_ALL_SKIP_KEYS.include?(k) }.each { |k|
|
47
|
-
new_cx.set_(k,cx[k])
|
48
|
-
}
|
49
|
-
ario.cx = new_cx
|
50
|
-
ario
|
51
|
-
end
|
52
|
-
def _add_cx(ario,keys)
|
53
|
-
new_cx = ario.cx
|
54
|
-
keys.each {|k|
|
55
|
-
next unless cx.has_key?(k)
|
56
|
-
new_cx.set_(k,cx[k])
|
57
|
-
}
|
58
|
-
ario.cx = new_cx
|
59
|
-
end
|
60
|
-
CX_DIR_ITER_KEYS = %w[sel nosel]
|
61
|
-
CX_STREAM_ITER_KEYS = %w[stream_rectype stream_itertype stream_sel stream_nosel]
|
62
|
-
def _add_iter_cx(ario)
|
63
|
-
if nostreamenum?
|
64
|
-
_add_cx(ario,CX_DIR_ITER_KEYS)
|
41
|
+
module Cx
|
42
|
+
module Methods
|
43
|
+
def _arg_skip(args)
|
44
|
+
#p callstr('_arg_skip',args,cx.inspect)
|
45
|
+
cx['ss_skipped'] = cx['ss_type'].sub(/^skip/,'') if cx['ss_type']
|
46
|
+
cx['ss_type'] = 'skip'
|
47
|
+
cx['skip_args'] = args
|
65
48
|
end
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
49
|
+
def _noarg_skip
|
50
|
+
cx['ss_skipped'] = cx['ss_type'].sub(/^skip/,'') if cx['ss_type']
|
51
|
+
cx['ss_type'] = 'skip'
|
52
|
+
cx['skipping'] = true
|
53
|
+
end
|
54
|
+
def skipping?() cx['skipping'] end
|
55
|
+
def skip(*args,&block)
|
56
|
+
if args.empty?
|
57
|
+
_noarg_skip
|
58
|
+
else
|
59
|
+
_arg_skip(args)
|
60
|
+
end
|
61
|
+
each(&block) if block_given?
|
62
|
+
self
|
74
63
|
end
|
75
|
-
|
76
|
-
ario
|
64
|
+
|
77
65
|
end
|
78
66
|
end
|
79
67
|
end
|
data/lib/rio/context/stream.rb
CHANGED
@@ -72,6 +72,7 @@ module RIO
|
|
72
72
|
else cx.set_('stream_itertype',rt)
|
73
73
|
end
|
74
74
|
end
|
75
|
+
|
75
76
|
def _set_selargs(sa,sel=true,&block)
|
76
77
|
key = (sel ? 'stream_sel' : 'stream_nosel')
|
77
78
|
cx[key] = sa
|
@@ -96,52 +97,73 @@ module RIO
|
|
96
97
|
_set_selargs(args,sel,&block)
|
97
98
|
end
|
98
99
|
|
100
|
+
def _sel()
|
101
|
+
!skipping?
|
102
|
+
end
|
103
|
+
def _sel_key(key)
|
104
|
+
(skipping? ? 'skip'+key : key)
|
105
|
+
end
|
99
106
|
public
|
100
107
|
|
101
108
|
def lines(*args,&block)
|
102
109
|
#p callstr('lines',*args)
|
103
|
-
|
104
|
-
|
110
|
+
if skipping?
|
111
|
+
cx['skipping'] = false
|
112
|
+
skiplines(*args,&block)
|
113
|
+
else
|
114
|
+
_set_sstype('lines')
|
115
|
+
_lines(args,_sel,&block)
|
116
|
+
end
|
105
117
|
end
|
106
118
|
def lines_(*args,&block)
|
107
119
|
#p callstr('lines_',*args)
|
108
120
|
_set_sstype('lines',false)
|
109
|
-
_lines(args,
|
121
|
+
_lines(args,_sel,false,&block)
|
110
122
|
end
|
111
123
|
|
112
124
|
def records(*args,&block)
|
113
|
-
|
114
|
-
|
125
|
+
if skipping?
|
126
|
+
cx['skipping'] = false
|
127
|
+
skiprecords(*args,&block)
|
128
|
+
else
|
129
|
+
_set_sstype('records')
|
130
|
+
_records(args,_sel,&block)
|
131
|
+
end
|
115
132
|
end
|
116
133
|
def records_(*args,&block)
|
117
134
|
_set_sstype('records',false)
|
118
|
-
_records(args,
|
135
|
+
_records(args,_sel,false,&block)
|
119
136
|
end
|
120
137
|
|
121
138
|
def rows(*args,&block)
|
122
|
-
|
123
|
-
|
139
|
+
if skipping?
|
140
|
+
cx['skipping'] = false
|
141
|
+
skiprows(*args,&block)
|
142
|
+
else
|
143
|
+
_set_sstype('rows')
|
144
|
+
_rows(args,_sel,&block)
|
145
|
+
end
|
124
146
|
end
|
125
147
|
def rows_(*args,&block)
|
126
148
|
_set_sstype('rows',false)
|
127
|
-
_rows(args,
|
149
|
+
_rows(args,_sel,false,&block)
|
128
150
|
end
|
129
151
|
|
130
152
|
|
131
|
-
def
|
132
|
-
#p callstr('
|
153
|
+
def skiplines(*args,&block)
|
154
|
+
#p callstr('skiplines',*args)
|
133
155
|
self.lines() unless args.empty? or cx.has_key?('stream_sel')
|
134
|
-
_set_sstype('
|
156
|
+
_set_sstype('skiplines')
|
135
157
|
_lines(args,false,&block)
|
136
158
|
end
|
137
|
-
def
|
159
|
+
def skiprecords(*args,&block)
|
138
160
|
self.records() unless args.empty? or cx.has_key?('stream_sel')
|
139
|
-
_set_sstype('
|
161
|
+
_set_sstype('skiprecords')
|
140
162
|
_records(args,false,&block)
|
141
163
|
end
|
142
|
-
def
|
164
|
+
def skiprows(*args,&block)
|
143
165
|
self.rows() unless args.empty? or cx.has_key?('stream_sel')
|
144
|
-
_set_sstype('
|
166
|
+
_set_sstype('skiprows')
|
145
167
|
_rows(args,false,&block)
|
146
168
|
end
|
147
169
|
|
data/lib/rio/cp.rb
CHANGED
@@ -79,7 +79,6 @@ module RIO
|
|
79
79
|
module Output
|
80
80
|
include InOut
|
81
81
|
|
82
|
-
|
83
82
|
protected
|
84
83
|
|
85
84
|
def cpfrom_obj_(obj)
|
@@ -119,7 +118,10 @@ module RIO
|
|
119
118
|
self
|
120
119
|
}
|
121
120
|
end
|
121
|
+
alias :copy_to :>
|
122
|
+
alias :append_to :>>
|
122
123
|
private
|
124
|
+
|
123
125
|
def _cpto_rio(arg,sym)
|
124
126
|
ario = ensure_rio(arg)
|
125
127
|
ario = ario.join(self.filename) if ario.dir?
|
@@ -132,10 +134,13 @@ module RIO
|
|
132
134
|
}
|
133
135
|
end
|
134
136
|
end
|
137
|
+
|
135
138
|
module Output
|
136
139
|
include Util::Output
|
137
140
|
def <<(arg) cpclose { _cpfrom(arg) } end
|
138
141
|
def <(arg) cpclose { _cpfrom(arg) } end
|
142
|
+
alias :copy_from :<
|
143
|
+
alias :append_from :<<
|
139
144
|
|
140
145
|
private
|
141
146
|
|
@@ -164,6 +169,8 @@ module RIO
|
|
164
169
|
include Util::Output
|
165
170
|
def <(arg) cpclose { self.iostate(:<) < arg } end
|
166
171
|
def <<(arg) cpclose { self.iostate(:<<) << arg } end
|
172
|
+
alias :copy_from :<
|
173
|
+
alias :append_from :<<
|
167
174
|
end
|
168
175
|
module Input
|
169
176
|
include Util::Input
|
@@ -173,6 +180,8 @@ module RIO
|
|
173
180
|
def >>(arg)
|
174
181
|
spcp(arg) || cpclose(arg) { self.iostate(:>>) >> arg }
|
175
182
|
end
|
183
|
+
alias :copy_to :>
|
184
|
+
alias :append_to :>>
|
176
185
|
def copy_as_file?(arg)
|
177
186
|
arg.kind_of?(Rio) and arg.scheme == 'ftp'
|
178
187
|
end
|
@@ -184,7 +193,6 @@ module RIO
|
|
184
193
|
nil
|
185
194
|
end
|
186
195
|
end
|
187
|
-
alias :copy :>
|
188
196
|
end
|
189
197
|
end
|
190
198
|
end
|
@@ -196,12 +204,15 @@ module RIO
|
|
196
204
|
include Util::Output
|
197
205
|
def <(arg) cpclose { self.iostate(:<) < arg } end
|
198
206
|
def <<(arg) cpclose { self.iostate(:<<) << arg } end
|
207
|
+
alias :copy_from :<
|
208
|
+
alias :append_from :<<
|
199
209
|
end
|
200
210
|
module Input
|
201
211
|
include Util::Input
|
202
212
|
def >(arg) cpclose(arg) { self.iostate(:>) > arg } end
|
203
213
|
def >>(arg) cpclose(arg) { self.iostate(:>>) >> arg } end
|
204
|
-
alias :
|
214
|
+
alias :copy_to :>
|
215
|
+
alias :append_to :>>
|
205
216
|
end
|
206
217
|
end
|
207
218
|
end
|
@@ -213,6 +224,8 @@ module RIO
|
|
213
224
|
include Util::Output
|
214
225
|
def <<(arg) _cpfrom(arg); self end
|
215
226
|
def <(arg) _cpfrom(arg); self end
|
227
|
+
alias :copy_from :<
|
228
|
+
alias :append_from :<<
|
216
229
|
|
217
230
|
private
|
218
231
|
|
@@ -225,7 +238,10 @@ module RIO
|
|
225
238
|
def _cpfrom_rio(ario)
|
226
239
|
#p callstr('_cpfrom_rio',ario)
|
227
240
|
dest = self.join(ario.filename)
|
228
|
-
|
241
|
+
case
|
242
|
+
when ario.symlink?
|
243
|
+
::File.symlink(ario.readlink.to_s,dest.to_s)
|
244
|
+
when ario.dir?
|
229
245
|
dest.mkdir
|
230
246
|
ario.nostreamenum.each do |el|
|
231
247
|
dest < el
|
@@ -251,7 +267,8 @@ module RIO
|
|
251
267
|
end
|
252
268
|
self
|
253
269
|
end
|
254
|
-
alias :
|
270
|
+
alias :copy_to :>
|
271
|
+
alias :append_to :>>
|
255
272
|
|
256
273
|
private
|
257
274
|
|
@@ -284,6 +301,8 @@ module RIO
|
|
284
301
|
_cpsrc(arg) << arg
|
285
302
|
end
|
286
303
|
end
|
304
|
+
alias :copy_from :<
|
305
|
+
alias :append_from :<<
|
287
306
|
|
288
307
|
private
|
289
308
|
|
data/lib/rio/dir.rb
CHANGED
@@ -115,9 +115,9 @@ module RIO
|
|
115
115
|
cx['retrystate'] = nil
|
116
116
|
self
|
117
117
|
end
|
118
|
-
|
119
|
-
|
120
|
-
|
118
|
+
|
119
|
+
def close_()
|
120
|
+
#p callstr('close_')+" ioh=#{self.ioh} open?=#{open?}"
|
121
121
|
return self unless self.open?
|
122
122
|
self.clear_selection
|
123
123
|
self.ioh.close
|
@@ -126,11 +126,12 @@ module RIO
|
|
126
126
|
self
|
127
127
|
end
|
128
128
|
protected :close_
|
129
|
-
|
129
|
+
|
130
|
+
CX_ENTRY_SEL_KEYS = %w[nostreamenum entry_sel skip_args ss_skipped]
|
130
131
|
def clear_selection()
|
131
|
-
|
132
|
-
|
133
|
-
|
132
|
+
CX_ENTRY_SEL_KEYS.each { |k|
|
133
|
+
cx.delete(k)
|
134
|
+
}
|
134
135
|
self
|
135
136
|
end
|
136
137
|
|
data/lib/rio/doc/HOWTO.rb
CHANGED
@@ -53,7 +53,7 @@ IO, File, Dir, Pathname, FileUtils, Tempfile, StringIO, OpenURI, Zlib, and CSV.
|
|
53
53
|
|
54
54
|
* Read a file into a string.
|
55
55
|
# method 1
|
56
|
-
string = ario.
|
56
|
+
string = ario.contents
|
57
57
|
# method 2
|
58
58
|
ario > string
|
59
59
|
|
@@ -61,7 +61,7 @@ IO, File, Dir, Pathname, FileUtils, Tempfile, StringIO, OpenURI, Zlib, and CSV.
|
|
61
61
|
# method 1
|
62
62
|
ario >> string
|
63
63
|
# method 2
|
64
|
-
string += ario.
|
64
|
+
string += ario.contents
|
65
65
|
|
66
66
|
* Read lines of a file into an array
|
67
67
|
# method 1
|
@@ -111,13 +111,13 @@ IO, File, Dir, Pathname, FileUtils, Tempfile, StringIO, OpenURI, Zlib, and CSV.
|
|
111
111
|
# method 1
|
112
112
|
rio('afile.gz').gzip > string
|
113
113
|
# method 2
|
114
|
-
string = rio('afile.gz').gzip.
|
114
|
+
string = rio('afile.gz').gzip.contents
|
115
115
|
|
116
116
|
* Append a gzipped file into a string
|
117
117
|
# method 1
|
118
118
|
rio('afile.gz').gzip >> string
|
119
119
|
# method 2
|
120
|
-
string += rio('afile.gz').gzip.
|
120
|
+
string += rio('afile.gz').gzip.contents
|
121
121
|
|
122
122
|
* Iterate through all the lines of a file
|
123
123
|
# method 1
|
@@ -132,7 +132,7 @@ IO, File, Dir, Pathname, FileUtils, Tempfile, StringIO, OpenURI, Zlib, and CSV.
|
|
132
132
|
rio('afile.gz').gzip { |line| ... }
|
133
133
|
|
134
134
|
* Iterate through all non-empty lines of a gzipped file, with each line chomped
|
135
|
-
rio('afile.gz').gzip.chomp.
|
135
|
+
rio('afile.gz').gzip.chomp.skiplines(:empty?) { |line| ... }
|
136
136
|
|
137
137
|
* Iterate through the first 100 lines of a file
|
138
138
|
# method 1
|
@@ -142,7 +142,7 @@ IO, File, Dir, Pathname, FileUtils, Tempfile, StringIO, OpenURI, Zlib, and CSV.
|
|
142
142
|
rio('afile.rb.gz').gzip.lines(0,/^\s*#/) { |line| ... }
|
143
143
|
|
144
144
|
* Iterate through the lines of a ruby file that are neither empty nor comments, with all lines chomped
|
145
|
-
rio('afile.rb.gz').chomp.
|
145
|
+
rio('afile.rb.gz').chomp.skiplines(/^\s*#/,:empty?) { |line| ... }
|
146
146
|
|
147
147
|
* Read all the comment lines from a ruby file into an array with all lines chomped
|
148
148
|
# method 1
|
@@ -155,7 +155,7 @@ IO, File, Dir, Pathname, FileUtils, Tempfile, StringIO, OpenURI, Zlib, and CSV.
|
|
155
155
|
# method 1
|
156
156
|
ario.chomp.lines(proc{ |line| line.length <= 1024}) > array
|
157
157
|
# method 2
|
158
|
-
array = ario.chomp.
|
158
|
+
array = ario.chomp.skiplines[proc{ |line| line.length > 1024}]
|
159
159
|
# method 3
|
160
160
|
array = ario.chomp.lines(proc{ |line| line.length <= 1024}).to_a
|
161
161
|
|
@@ -240,21 +240,21 @@ IO, File, Dir, Pathname, FileUtils, Tempfile, StringIO, OpenURI, Zlib, and CSV.
|
|
240
240
|
# method 2
|
241
241
|
array = ario.lines[proc{ |l| l.length > 128}]
|
242
242
|
# method 3
|
243
|
-
array = ario.
|
243
|
+
array = ario.skiplines[proc{ |l| l.length <= 128}]
|
244
244
|
|
245
245
|
* Copy all lines that do not start with 'zippy' into another file
|
246
246
|
# method 1
|
247
|
-
ario.
|
247
|
+
ario.skiplines(/^zippy/) > rio('another_file')
|
248
248
|
# method 2
|
249
|
-
ario.lines.
|
249
|
+
ario.lines.skiplines(/^zippy/) > rio('another_file')
|
250
250
|
# method 3
|
251
|
-
rio('another_file') < ario.
|
251
|
+
rio('another_file') < ario.skiplines(/^zippy/)
|
252
252
|
|
253
253
|
* Copy the first 10 lines and lines starting with 'zippy', but exclude any lines longer than 128 bytes
|
254
254
|
# method 1
|
255
|
-
ario.lines(0...10,/^zippy/).
|
255
|
+
ario.lines(0...10,/^zippy/).skiplines(proc{ |l| l.length > 128}] > rio('another_file')
|
256
256
|
# method 2
|
257
|
-
rio('another_file') < ario.lines(0...10,/^zippy/).
|
257
|
+
rio('another_file') < ario.lines(0...10,/^zippy/).skiplines(proc{ |l| l.length > 128})
|
258
258
|
|
259
259
|
|
260
260
|
|
@@ -313,19 +313,19 @@ IO, File, Dir, Pathname, FileUtils, Tempfile, StringIO, OpenURI, Zlib, and CSV.
|
|
313
313
|
|
314
314
|
* Put all files excluding those that are symlinks to files in an array
|
315
315
|
# method 1
|
316
|
-
array = ario.
|
316
|
+
array = ario.skipfiles[:symlink?]
|
317
317
|
# method 2
|
318
|
-
array = ario.
|
318
|
+
array = ario.skipfiles(:symlink?).files[]
|
319
319
|
# method 3
|
320
|
-
array = ario.
|
320
|
+
array = ario.skipfiles(:symlink?).to_a
|
321
321
|
# method 4
|
322
|
-
array = ario.files.
|
322
|
+
array = ario.files.skipfiles[:symlink?]
|
323
323
|
|
324
324
|
* Put all entries that are not files (or symlinks to files) into an array
|
325
325
|
# method 1
|
326
|
-
array = ario.
|
326
|
+
array = ario.skipfiles[]
|
327
327
|
# method 2
|
328
|
-
array = ario.
|
328
|
+
array = ario.skipfiles.to_a
|
329
329
|
|
330
330
|
* Put all entries that are symlinks to files into an array
|
331
331
|
# method 1
|
@@ -335,15 +335,15 @@ IO, File, Dir, Pathname, FileUtils, Tempfile, StringIO, OpenURI, Zlib, and CSV.
|
|
335
335
|
|
336
336
|
* Put all directories except those named '.svn' into an array
|
337
337
|
# method 1
|
338
|
-
array = ario.
|
338
|
+
array = ario.skipdirs['.svn']
|
339
339
|
# method 2
|
340
|
-
array = ario.
|
340
|
+
array = ario.skipdirs[/^\.svn/]
|
341
341
|
# method 3
|
342
|
-
array = ario.
|
342
|
+
array = ario.skipdirs('.svn').to_a
|
343
343
|
# method 4
|
344
|
-
array = ario.
|
344
|
+
array = ario.skipdirs('.svn').dirs[]
|
345
345
|
# method 5
|
346
|
-
array = ario.
|
346
|
+
array = ario.skipdirs('.svn')[]
|
347
347
|
|
348
348
|
|
349
349
|
---
|
@@ -359,7 +359,7 @@ IO, File, Dir, Pathname, FileUtils, Tempfile, StringIO, OpenURI, Zlib, and CSV.
|
|
359
359
|
# method 2
|
360
360
|
rio('dstfile') < rio('srcfile')
|
361
361
|
# method 3
|
362
|
-
rip('dstfile').print!(rio('srcfile').
|
362
|
+
rip('dstfile').print!(rio('srcfile').contents)
|
363
363
|
|
364
364
|
* Append the contents of one file to another file
|
365
365
|
# method 1
|
@@ -367,7 +367,7 @@ IO, File, Dir, Pathname, FileUtils, Tempfile, StringIO, OpenURI, Zlib, and CSV.
|
|
367
367
|
# method 2
|
368
368
|
rio('dstfile') << rio('srcfile')
|
369
369
|
# method 3
|
370
|
-
rip('dstfile').a.print!(rio('srcfile').
|
370
|
+
rip('dstfile').a.print!(rio('srcfile').contents)
|
371
371
|
|
372
372
|
* Copy the first 10 lines of one file to another file
|
373
373
|
# method 1
|
@@ -389,7 +389,7 @@ IO, File, Dir, Pathname, FileUtils, Tempfile, StringIO, OpenURI, Zlib, and CSV.
|
|
389
389
|
# method 2
|
390
390
|
rio('afile') < rio('http://ruby-doc.org/')
|
391
391
|
# method 3
|
392
|
-
rio('afile').print!(rio('http://ruby-doc.org/').
|
392
|
+
rio('afile').print!(rio('http://ruby-doc.org/').contents)
|
393
393
|
|
394
394
|
* Append the output of the daytime server running on the localhost to a file
|
395
395
|
# method 1
|
@@ -416,7 +416,7 @@ IO, File, Dir, Pathname, FileUtils, Tempfile, StringIO, OpenURI, Zlib, and CSV.
|
|
416
416
|
# method 2
|
417
417
|
rio('afile.gz').gzip < rio('afile')
|
418
418
|
# method 3
|
419
|
-
rio('afile.gz').gzip.print!( rio('afile').
|
419
|
+
rio('afile.gz').gzip.print!( rio('afile').contents )
|
420
420
|
|
421
421
|
* Create an ungzipped copy of a gzipped file
|
422
422
|
# method 1
|
@@ -424,7 +424,7 @@ IO, File, Dir, Pathname, FileUtils, Tempfile, StringIO, OpenURI, Zlib, and CSV.
|
|
424
424
|
# method 2
|
425
425
|
rio('afile.gz').gzip > rio('afile')
|
426
426
|
# method 3
|
427
|
-
rio('afile').print!( rio('afile.gz').gzip.
|
427
|
+
rio('afile').print!( rio('afile.gz').gzip.contents )
|
428
428
|
|
429
429
|
* Copy the first 100 lines of gzipped file on a webserver into a local file
|
430
430
|
# method 1
|
@@ -448,9 +448,9 @@ IO, File, Dir, Pathname, FileUtils, Tempfile, StringIO, OpenURI, Zlib, and CSV.
|
|
448
448
|
|
449
449
|
* Count the lines of code in a directory tree of ruby source files
|
450
450
|
# method 1
|
451
|
-
cnt = ario.all.files('*.rb').chomp.
|
451
|
+
cnt = ario.all.files('*.rb').chomp.skiplines(/^\s*#/,/^\s*$/).inject(0) { |sum,l| sum += 1 }
|
452
452
|
# method 2
|
453
|
-
cnt = ario.all.files('*.rb').chomp.
|
453
|
+
cnt = ario.all.files('*.rb').chomp.skiplines[/^\s*#/,/^\s*$/].size
|
454
454
|
|
455
455
|
* Concatanate the contents of all .txt files in a directory into an array
|
456
456
|
# method 1
|
@@ -548,7 +548,7 @@ IO, File, Dir, Pathname, FileUtils, Tempfile, StringIO, OpenURI, Zlib, and CSV.
|
|
548
548
|
# method 4
|
549
549
|
rio(?-) < rio('afile')
|
550
550
|
# method 5
|
551
|
-
rio(?-).print(rio('afile').
|
551
|
+
rio(?-).print(rio('afile').contents)
|
552
552
|
|
553
553
|
* Emulate a simplified unix 'head' command which reads from stdin and writes the first 10 lines to stdout
|
554
554
|
# method 1
|
@@ -560,7 +560,7 @@ IO, File, Dir, Pathname, FileUtils, Tempfile, StringIO, OpenURI, Zlib, and CSV.
|
|
560
560
|
|
561
561
|
* Read the output of the 'ps' command into an array without the header line or the line representing
|
562
562
|
the 'ps' command itself
|
563
|
-
ps = rio(?-,'ps -a').
|
563
|
+
ps = rio(?-,'ps -a').skiplines[0,/ps$/]
|
564
564
|
|
565
565
|
* Run an external program, copying its input from one location and its output from another,
|
566
566
|
and make it look very much like a shell command.
|