riel 1.1.11 → 1.1.12
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/riel/asciitable/row.rb +2 -4
- data/lib/riel/enumerable.rb +6 -8
- data/lib/riel/file.rb +1 -1
- data/lib/riel/optproc.rb +11 -47
- data/lib/riel/string.rb +1 -1
- data/lib/riel.rb +1 -1
- data/test/riel/dir_test.rb +0 -11
- data/test/riel/optproc_test.rb +3 -3
- data/test/riel/rcfile_test.rb +0 -3
- data/test/riel/text_test.rb +1 -1
- data/test/riel/timer_test.rb +2 -2
- metadata +4 -4
data/lib/riel/asciitable/row.rb
CHANGED
@@ -45,7 +45,7 @@ module RIEL
|
|
45
45
|
end
|
46
46
|
|
47
47
|
def print
|
48
|
-
banner = (0 .. @table.last_column).collect { |col|
|
48
|
+
banner = (0 .. @table.last_column).collect { |col| BannerCell.new(@char, col, 1) }
|
49
49
|
bannervalues = banner.collect_with_index do |bc, col|
|
50
50
|
width = @table.column_width col
|
51
51
|
bc.formatted_value width, :center
|
@@ -60,8 +60,6 @@ module RIEL
|
|
60
60
|
lastdatarow = table.data_rows.last
|
61
61
|
statrownum = table.last_row + 1
|
62
62
|
|
63
|
-
nrows = lastdatarow + 1 - firstdatarow
|
64
|
-
|
65
63
|
super table, statrownum
|
66
64
|
|
67
65
|
ncolumns = @table.last_column
|
@@ -99,7 +97,7 @@ module RIEL
|
|
99
97
|
def calculate col, fromrow, torow
|
100
98
|
nrows = torow + 1 - fromrow
|
101
99
|
total = @table.column(col).total fromrow, torow
|
102
|
-
|
100
|
+
total / nrows
|
103
101
|
end
|
104
102
|
end
|
105
103
|
end
|
data/lib/riel/enumerable.rb
CHANGED
@@ -2,8 +2,7 @@
|
|
2
2
|
# -*- ruby -*-
|
3
3
|
|
4
4
|
module Enumerable
|
5
|
-
|
6
|
-
def collect_with_index(&blk)
|
5
|
+
def collect_with_index &blk
|
7
6
|
ary = []
|
8
7
|
self.each_with_index do |item, idx|
|
9
8
|
ary << blk.call(item, idx)
|
@@ -13,7 +12,7 @@ module Enumerable
|
|
13
12
|
|
14
13
|
NOT_NIL = Object.new
|
15
14
|
|
16
|
-
def select_with_index
|
15
|
+
def select_with_index arg = NOT_NIL, &blk
|
17
16
|
ary = []
|
18
17
|
self.each_with_index do |item, idx|
|
19
18
|
ary << item if _match?(arg, item, idx, &blk)
|
@@ -21,7 +20,7 @@ module Enumerable
|
|
21
20
|
ary
|
22
21
|
end
|
23
22
|
|
24
|
-
def detect_with_index
|
23
|
+
def detect_with_index arg = NOT_NIL, &blk
|
25
24
|
self.each_with_index do |item, idx|
|
26
25
|
return item if _match?(arg, item, idx, &blk)
|
27
26
|
end
|
@@ -35,7 +34,7 @@ module Enumerable
|
|
35
34
|
|
36
35
|
origw = $-w
|
37
36
|
$-w = false
|
38
|
-
def select
|
37
|
+
def select arg = NOT_NIL, &blk
|
39
38
|
ary = []
|
40
39
|
self.each_with_index do |item, idx|
|
41
40
|
ary << item if _match?(arg, item, idx, &blk)
|
@@ -43,7 +42,7 @@ module Enumerable
|
|
43
42
|
ary
|
44
43
|
end
|
45
44
|
|
46
|
-
def detect
|
45
|
+
def detect arg = NOT_NIL, &blk
|
47
46
|
self.each_with_index do |item, idx|
|
48
47
|
return item if _match?(arg, item, idx, &blk)
|
49
48
|
end
|
@@ -51,7 +50,7 @@ module Enumerable
|
|
51
50
|
end
|
52
51
|
$-w = origw
|
53
52
|
|
54
|
-
def _match?
|
53
|
+
def _match? arg, item, idx, &blk
|
55
54
|
if blk
|
56
55
|
args = [ item ]
|
57
56
|
args << idx if idx && blk.arity > 1
|
@@ -62,5 +61,4 @@ module Enumerable
|
|
62
61
|
arg == item
|
63
62
|
end
|
64
63
|
end
|
65
|
-
|
66
64
|
end
|
data/lib/riel/file.rb
CHANGED
data/lib/riel/optproc.rb
CHANGED
@@ -7,7 +7,6 @@ require 'riel/text'
|
|
7
7
|
require 'riel/enumerable'
|
8
8
|
|
9
9
|
module OptProc
|
10
|
-
|
11
10
|
class Option
|
12
11
|
include Loggable
|
13
12
|
|
@@ -101,8 +100,7 @@ module OptProc
|
|
101
100
|
def match args, opt = args[0]
|
102
101
|
return nil unless %r{^-}.match opt
|
103
102
|
|
104
|
-
tag
|
105
|
-
tag ||= opt
|
103
|
+
tag = opt.split('=', 2)[0] || opt
|
106
104
|
|
107
105
|
@md = nil
|
108
106
|
|
@@ -114,7 +112,7 @@ module OptProc
|
|
114
112
|
end
|
115
113
|
|
116
114
|
def set_value args, opt = args[0]
|
117
|
-
|
115
|
+
val = opt.split('=', 2)[1]
|
118
116
|
args.shift
|
119
117
|
|
120
118
|
if @md
|
@@ -143,8 +141,6 @@ module OptProc
|
|
143
141
|
args.shift
|
144
142
|
end
|
145
143
|
end
|
146
|
-
else
|
147
|
-
# log { "no type" }
|
148
144
|
end
|
149
145
|
|
150
146
|
value = value_from_match
|
@@ -188,22 +184,16 @@ module OptProc
|
|
188
184
|
end
|
189
185
|
|
190
186
|
def to_boolean val
|
191
|
-
%w{ yes true on soitenly }.include?
|
187
|
+
%w{ yes true on soitenly }.include? val.downcase
|
192
188
|
end
|
193
189
|
|
194
190
|
def set val, opt = nil, args = nil
|
195
|
-
# log { "argtype: #{@argtype}; md: #{@md.inspect}" }
|
196
|
-
|
197
191
|
setargs = [ val, opt, args ].select_with_index { |x, i| i < @set.arity }
|
198
|
-
# log "val: #{val}"
|
199
192
|
@set.call(*setargs)
|
200
193
|
end
|
201
194
|
end
|
202
195
|
|
203
|
-
|
204
196
|
class OptionSet
|
205
|
-
include Loggable
|
206
|
-
|
207
197
|
attr_reader :options
|
208
198
|
|
209
199
|
def initialize data
|
@@ -238,20 +228,6 @@ module OptProc
|
|
238
228
|
end
|
239
229
|
end
|
240
230
|
end
|
241
|
-
|
242
|
-
if false
|
243
|
-
[ @longopts, @shortopts ].each do |list|
|
244
|
-
list.each_with_index do |v, idx|
|
245
|
-
log { "#{idx} => #{v.inspect}" }
|
246
|
-
end
|
247
|
-
end
|
248
|
-
[ @regexps ].each do |map|
|
249
|
-
map.each do |k, v|
|
250
|
-
log { "#{k} => #{v.inspect}" }
|
251
|
-
end
|
252
|
-
end
|
253
|
-
end
|
254
|
-
|
255
231
|
end
|
256
232
|
|
257
233
|
COMBINED_OPTS_RES = [
|
@@ -264,14 +240,9 @@ module OptProc
|
|
264
240
|
def process_option args
|
265
241
|
opt = args[0]
|
266
242
|
|
267
|
-
# log { "processing option #{opt}" }
|
268
|
-
|
269
243
|
if md = COMBINED_OPTS_RES.collect { |re| re.match opt }.detect
|
270
244
|
lhs = md[1]
|
271
245
|
rhs = "-" + md[2]
|
272
|
-
|
273
|
-
# log { "lhs, rhs: #{lhs.inspect}, #{rhs.inspect}" }
|
274
|
-
|
275
246
|
args[0, 1] = lhs, rhs
|
276
247
|
|
277
248
|
return process_option args
|
@@ -286,7 +257,6 @@ module OptProc
|
|
286
257
|
@shortopts[ch]
|
287
258
|
end
|
288
259
|
|
289
|
-
# log { "opts: #{assocopts.inspect}" }
|
290
260
|
if assocopts && x = set_option(assocopts, args)
|
291
261
|
return x
|
292
262
|
end
|
@@ -295,9 +265,6 @@ module OptProc
|
|
295
265
|
if x = set_option(@options, args)
|
296
266
|
return x
|
297
267
|
elsif @bestmatch
|
298
|
-
# what's the best match here ...?
|
299
|
-
log { "bestmatch: #{@bestmatch}" }
|
300
|
-
log { "bestopts : #{@bestopts.inspect}" }
|
301
268
|
if @bestopts.size == 1
|
302
269
|
@bestopts[0].set_value args
|
303
270
|
return @bestopts[0]
|
@@ -316,20 +283,17 @@ module OptProc
|
|
316
283
|
@bestopts = Array.new
|
317
284
|
|
318
285
|
optlist.each do |option|
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
end
|
286
|
+
next unless mv = option.match(args)
|
287
|
+
if mv >= 1.0
|
288
|
+
# exact match:
|
289
|
+
option.set_value args
|
290
|
+
return option
|
291
|
+
elsif !@bestmatch || @bestmatch <= mv
|
292
|
+
@bestmatch = mv
|
293
|
+
@bestopts << option
|
328
294
|
end
|
329
295
|
end
|
330
296
|
nil
|
331
297
|
end
|
332
|
-
|
333
298
|
end
|
334
|
-
|
335
299
|
end
|
data/lib/riel/string.rb
CHANGED
data/lib/riel.rb
CHANGED
data/test/riel/dir_test.rb
CHANGED
@@ -27,17 +27,6 @@ class DirTestCase < Test::Unit::TestCase
|
|
27
27
|
testdir.mkdir
|
28
28
|
assert testdir.exist?
|
29
29
|
|
30
|
-
# create a structure like this:
|
31
|
-
layout = [
|
32
|
-
:a => [
|
33
|
-
:a0 => %w{ a00 a01 a02 }
|
34
|
-
],
|
35
|
-
:b => [
|
36
|
-
:b0 => %w{ },
|
37
|
-
:b1 => %w{ b10 b11 }
|
38
|
-
]
|
39
|
-
]
|
40
|
-
|
41
30
|
a = testdir + 'a'
|
42
31
|
a.mkdir
|
43
32
|
(0 .. 5).each do |ai|
|
data/test/riel/optproc_test.rb
CHANGED
@@ -205,9 +205,9 @@ class OptProcTestCase < Test::Unit::TestCase
|
|
205
205
|
|
206
206
|
def test_value_regexp
|
207
207
|
@range_start = nil
|
208
|
-
opt = OptProc::Option.new(:tags
|
209
|
-
:arg
|
210
|
-
:set
|
208
|
+
opt = OptProc::Option.new(:tags => %w{ --after },
|
209
|
+
:arg => [ :required, :regexp, %r{ ^ (\d+%?) $ }x ],
|
210
|
+
:set => Proc.new { |md| @range_start = md[1] })
|
211
211
|
|
212
212
|
%w{ 5 5% 10 90% }.each do |rg|
|
213
213
|
[
|
data/test/riel/rcfile_test.rb
CHANGED
@@ -31,10 +31,7 @@ class RCFileTestCase < Test::Unit::TestCase
|
|
31
31
|
|
32
32
|
rc = RCFile.new tempfile
|
33
33
|
(0 ... num).each do |i|
|
34
|
-
key = "name#{i}"
|
35
34
|
assert_not_nil rc.settings[i]
|
36
|
-
pair = rc.settings[i]
|
37
|
-
|
38
35
|
assert_equal [ "name#{i}", "value#{i}" ], rc.settings[i]
|
39
36
|
end
|
40
37
|
end
|
data/test/riel/text_test.rb
CHANGED
data/test/riel/timer_test.rb
CHANGED
@@ -21,7 +21,7 @@ class TimerTestCase < Test::Unit::TestCase
|
|
21
21
|
def test_to_stdout
|
22
22
|
orig_out = $stdout
|
23
23
|
$stdout = StringIO.new
|
24
|
-
|
24
|
+
Timer.new(TIMER_STRING) do
|
25
25
|
sleep 0.1
|
26
26
|
end
|
27
27
|
|
@@ -32,7 +32,7 @@ class TimerTestCase < Test::Unit::TestCase
|
|
32
32
|
|
33
33
|
def test_to_io
|
34
34
|
stringio = StringIO.new
|
35
|
-
|
35
|
+
Timer.new("sleep for a second", :io => stringio) do
|
36
36
|
sleep 0.1
|
37
37
|
end
|
38
38
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: riel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 11
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 1.1.
|
9
|
+
- 12
|
10
|
+
version: 1.1.12
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Jeff Pace
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-11-
|
18
|
+
date: 2012-11-23 00:00:00 -05:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|