rbfind 2.2 → 2.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 75ec1222c8e64f36c9927aa96c1c4f2a737d624d142fea22bfce274637074a7b
4
- data.tar.gz: 6c34e268c249977c6c74dc3bf42d841ea63c2649274742be29918a1c19d592a0
3
+ metadata.gz: f0a448408396d2339b4aa0656dfeb579c6533373623ca9e6cb0e4b48812e2b03
4
+ data.tar.gz: d71f32510fdc92315c7f5aaa16d08560d6bc6b1d9515af85913f3c4a4f42e6ba
5
5
  SHA512:
6
- metadata.gz: c71fdaa76238ddae6fcc6b887bf30280f7f48c97e92d324ad5a400f81de8038f4fbe1b10ff931e4cc8f80604d69e71e496a80f99544ff5ba5a37ad0beb1dc2ea
7
- data.tar.gz: b12aad69797682840b1a75b07b77f5474d5aab8e66b4b536dfe41e538e7f5fee493aaf5ad493db8419454532729600acc037e0936001b193d7911a44ac886f73
6
+ metadata.gz: bab39e437deaa7cf9d4e283f83c5ee354c3f28b4ed7159b90adfdcc7210c2dfce80593cfadcceb3c0702c4641c93b66b4fd2e4351deccd62adb9267754aaf588
7
+ data.tar.gz: 44adde8bccbb1f840187bb9973a7e835d098f05c715fa22cf493a06fa8c00bc5bdbdb7e0d5da77db925034f3315f16148fd7431ed8b745febaeaadda0d5fd560
data/bin/rbfind CHANGED
@@ -33,13 +33,17 @@ module RbFind
33
33
  [ %w(--depth -d), nil, "yield directory after its contents"],
34
34
  [ %w(--maxdepth -m), :num, "maxium step depth"],
35
35
  [ %w(--follow -y), nil, "follow symbolic links"],
36
- [ %w(--nosort -S), nil, "unsorted"],
37
- [ %w(--sort-by -s), :str, "sort expression ('n' is name)"],
38
- [ %w(--reverse -R), :str, "reverse sort"],
36
+ [ %w(--nosort -U), nil, "unsorted"],
37
+ [ %w(--sort-by -s), :str, "sort expression"],
38
+ [ %w(--reverse -R), nil, "reverse the sort"],
39
+ [ %w(--time -t), nil, "sort by time, newest first"],
40
+ [ %w(--size -S), nil, "sort by size, largest first"],
41
+ [ %w(--dirs -F), nil, "sort directories before files"],
39
42
  [ %w(--require -r), :rb, "require library"],
40
43
  [ %w(--puts-path -p), nil, "do 'puts path/cpath' on true block"],
41
44
  [ %w(--ls-l -P), nil, "do 'ls -l' style output on true block"],
42
- [ %w(--wider -+), nil, "widen fields in long output format (--ls-l)"],
45
+ [ %w(--long -Q), nil, "alternate long format on true block"],
46
+ [ %w(--wider -+), nil, "widen fields in long output format"],
43
47
  [ %w(--slash -/), nil, "append a slash to directory names"],
44
48
  [ %w(--lines -l), :blk, "surround block by 'lines { |$_,$.| ... }'"],
45
49
  [ %w(--reallines -L), :blk, "same as -l but stop at any null character"],
@@ -48,14 +52,15 @@ module RbFind
48
52
  [ %w(--binary -b), nil, "grep even binary files"],
49
53
  [ %w(--no-vcs -C), nil, "prune version control dirs (CVS/.svn/.git)"],
50
54
  [ %w(--no-swap -W), nil, "ignore Vim swapfiles"],
51
- [ %w(--skip -k), :lst, "filenames to skip"],
52
- [ %w(--demand -D), :lst, "skip all filenames but these"],
55
+ [ %w(--skip -k), :rgx, "filenames to skip"],
56
+ [ %w(--demand -D), :rgx, "skip all filenames but these"],
53
57
  [ %w(--ext -e), :lst, "skip all filename extensions but these"],
54
58
  [ %w(--visible -I), nil, "skip all hidden (starting with .dot)"],
59
+ [ %w(--all -a), nil, "all, including hidden (starting with .dot)"],
55
60
  [ %w(--nodirs -N), nil, "skip directories"],
56
61
  [ %w(--begin -B), :blk, "eval block before begin"],
57
62
  [ %w(--end -E), :blk, "eval block after end"],
58
- [ %w(--file -f), :blk, "read block expression from file"],
63
+ [ %w(--file -f), :nam, "read block expression from file"],
59
64
  [ %w(--encoding -K), :str, "encoding extern[:intern] (same as ruby -E)"],
60
65
  ]
61
66
 
@@ -81,12 +86,16 @@ module RbFind
81
86
  when '--maxdepth' then @params[ :max_depth] = arg.to_i
82
87
  when '--follow' then @params[ :follow] = true
83
88
  when '--nosort' then @params[ :sort] = false
84
- when '--sort-by' then @params[ :sort] = instance_eval "proc { |n| #{arg} }"
89
+ when '--sort-by' then @params[ :sort] = instance_eval "proc { #{arg} }"
90
+ when '--time' then @params[ :sort] = proc { mtime } ; @params[ :reverse] = true
91
+ when '--size' then @params[ :sort] = proc { size } ; @params[ :reverse] = true
92
+ when '--dirs' then @params[ :dirs] = true
85
93
  when '--reverse' then @params[ :reverse] = true
86
94
  when '--require' then require arg
87
95
  when '--puts-path' then @puts = true
88
- when '--ls-l' then @puts = true ; @wd = 6
89
- when '--wider' then @wd = @wd ? @wd.succ : 4
96
+ when '--ls-l' then @puts = :ls ; @wds = 6 ; @wd = 6
97
+ when '--long' then @puts = :alt ; @wds = 7 ; @wd = 4
98
+ when '--wider' then @wd and @wd += 2.succ ; @wds and @wds += @puts == :alt ? 4 : 3
90
99
  when '--slash' then @slash = true
91
100
  when '--lines' then @lines = :plain ; @block = arg
92
101
  when '--reallines' then @lines = :plain ; @real = true ; @block = arg
@@ -99,6 +108,7 @@ module RbFind
99
108
  when '--demand' then @demand = arg
100
109
  when '--ext' then @ext = arg
101
110
  when '--visible' then @visible = true
111
+ when '--all' then @visible = false
102
112
  when '--nodirs' then @nodirs = true
103
113
  when '--begin' then @blkbegin = arg
104
114
  when '--end' then @blkend = arg
@@ -142,7 +152,7 @@ module RbFind
142
152
  @binary or @block = "not binary? and (#@block)"
143
153
 
144
154
  else
145
- @block ||= if @args.last and not (File.exists? @args.last) then
155
+ @block ||= if @args.last and not (File.lstat @args.last rescue false) then
146
156
  @args.pop.dup
147
157
  else
148
158
  @puts ||= true
@@ -150,11 +160,15 @@ module RbFind
150
160
  end
151
161
  if @puts then
152
162
  @block = "( #@block ) and "
153
- @block << if @wd then
154
- "spcsep stype+modes, user.w#@wd, group.w#@wd, size.w#@wd, " +
155
- "mtime.lsish, #{opath} + #{co ? 'carrow' : 'arrow'}.to_s"
156
- else
157
- "puts #{opath}"
163
+ @block << case @puts
164
+ when :alt then
165
+ "spcsep stype+modes, user!.w#@wd, group!.w#@wd, size.w_#@wds, " +
166
+ "mtime.long, #{opath} + #{co ? 'carrow' : 'arrow'}.to_s"
167
+ when :ls then
168
+ "spcsep stype+modes, user.w#@wd, group.w#@wd, size.w#@wds, " +
169
+ "mtime.lsish, #{opath} + #{co ? 'carrow' : 'arrow'}.to_s"
170
+ else
171
+ "puts #{opath}"
158
172
  end
159
173
  end
160
174
 
@@ -246,7 +260,7 @@ module RbFind
246
260
  $ rbfind -d -m3 -- /mnt/data
247
261
  $ rbfind 'filesize > 10.MiB and colsep size.to_hib, path'
248
262
 
249
- $ rbfind -S "name =~ /^\.*/ ; $'.downcase"
263
+ $ rbfind -U "name =~ /^\.*/ ; $'.downcase"
250
264
  $ rbfind -B '$s=0' -E 'puts $s.to_h' 'filesize {|s|$s+=s}'
251
265
  $ rbfind 'puts path if ext == ".rb"'
252
266
  $ rbfind -p 'ext == ".rb"'
@@ -447,8 +461,9 @@ class Integer
447
461
  # convenient formatting, right justification
448
462
  def method_missing sym, *args
449
463
  case sym.to_s # .to_s for Ruby 1.8
450
- when /\Aw_?(\d+)/ then "%#{$1}d" % self
451
- else super
464
+ when /\Aw(\d+)/ then "%#{$1}d" % self
465
+ when /\Aw_(\d+)/ then to_g.rjust $1.to_i
466
+ else super
452
467
  end
453
468
  end
454
469
  end
@@ -483,6 +498,20 @@ class NilClass
483
498
  end
484
499
  end
485
500
 
501
+ class TrueClass
502
+ def <=> oth
503
+ oth == true ? 0 : oth == false ? 1 : nil
504
+ end
505
+ include Enumerable
506
+ end
507
+
508
+ class FalseClass
509
+ def <=> oth
510
+ oth == false ? 0 : oth == true ? -1 : nil
511
+ end
512
+ include Enumerable
513
+ end
514
+
486
515
  class Proc
487
516
  def to_s
488
517
  "#<%s:0x%08x>" % [ self.class, object_id]
data/lib/rbfind.rb CHANGED
@@ -8,7 +8,7 @@ require "rbfind/csv"
8
8
 
9
9
  module RbFind
10
10
 
11
- VERSION = "2.2".freeze
11
+ VERSION = "2.6".freeze
12
12
 
13
13
  =begin rdoc
14
14
 
@@ -241,7 +241,7 @@ Reverse sort:
241
241
 
242
242
  Sort without case sensitivity and preceding dot:
243
243
 
244
- s = proc { |x| x =~ /^\.?/ ; $'.downcase }
244
+ s = proc { name =~ /^\.?/ ; $'.downcase }
245
245
  RbFind.run sort: s do
246
246
  puts path
247
247
  end
@@ -270,36 +270,30 @@ Sort without case sensitivity and preceding dot:
270
270
 
271
271
  private
272
272
 
273
- def initialize max_depth: nil, depth_first: nil, follow: nil,
274
- sort: true, reverse: false, error: nil, &block
275
- @max_depth = max_depth
276
- @depth_first = depth_first
277
- @follow = follow
278
- @sort = sort_parser sort, reverse
279
- @error = error
280
- @block = block
281
-
282
- ostat = $stdout.stat
283
- @ostat = ostat if ostat.file?
284
-
285
- @wd, @start, @count = Dir.getwd, Time.now, 0
286
- end
273
+ Params = Struct.new :max_depth, :depth_first, :follow,
274
+ :sort, :dirs, :reverse, :error, :block
287
275
 
288
- def sort_parser st, rev
289
- r = case st
290
- when Proc then proc { |l| l.sort_by! &st }
291
- when nil, false, nil, "" then proc { }
292
- else proc { |l| l.sort! }
276
+ def initialize max_depth: nil, depth_first: nil, follow: nil,
277
+ sort: true, dirs: false, reverse: false, error: nil, &block
278
+ @params = Params.new max_depth, depth_first, follow,
279
+ (sort_parser sort), dirs, reverse, error, block
280
+ @start = Time.instance_eval { @start = Time.now }
281
+ Time.instance_eval { @start = Time.now }
282
+ @count, @depth = 0, 0
283
+ end
284
+
285
+ def sort_parser st
286
+ case st
287
+ when Proc then proc { |l| l.sort_by! { |e| e.instance_eval &st } }
288
+ when String then proc { |l| l.sort_by! { |e| e.instance_eval st } }
289
+ when nil, false then proc { }
290
+ else proc { |l| l.sort_by! { |e| e.name } }
293
291
  end
294
- rev ? proc { |l| r.call l ; l.reverse! } : r
295
292
  end
296
293
 
297
294
  public
298
295
 
299
- attr_reader :wd, :start, :count, :depth
300
-
301
296
  def run *args
302
- @levels, @depth = [], 0
303
297
  args.flatten!
304
298
  args.compact!
305
299
  if args.empty? then
@@ -307,94 +301,69 @@ Sort without case sensitivity and preceding dot:
307
301
  else
308
302
  args.each { |base|
309
303
  handle_error do
310
- File.exists? base or raise "`#{base}` doesn't exist."
311
- visit_depth base
304
+ File.lstat base rescue raise "`#{base}` doesn't exist."
305
+ e = Entry.new base, self
306
+ enter e
312
307
  end
313
308
  }
314
309
  end
315
- ensure
316
- @levels = @depth = nil
317
310
  end
318
311
 
312
+ attr_reader :start, :count
313
+ attr_reader :depth
314
+ attr_reader :current
315
+
319
316
  private
320
317
 
321
- def join_path
322
- (File.join @levels).freeze
318
+ def enter elem
319
+ c_, @current = @current, elem
320
+ @count += 1
321
+ visit_depth
322
+ ensure
323
+ @current = c_
323
324
  end
324
325
 
325
- def visit filename
326
- @depth += 1
327
- visit_depth filename
328
- ensure
329
- @depth -= 1
326
+ def visit_dir dir
327
+ return if @params.max_depth and @params.max_depth == @depth
328
+ list = (Dir.new dir).children.map { |f| Entry.new f, self }
329
+ @params.sort.call list
330
+ @params.reverse and list.reverse!
331
+ @params.dirs and list = list.partition { |e| e.rstat.directory? }.flatten
332
+ begin
333
+ @depth += 1
334
+ list.each { |e| enter e }
335
+ ensure
336
+ @depth -= 1
337
+ end
330
338
  end
331
339
 
332
- def visit_depth filename
333
- @levels.push filename.dup.freeze
334
- p_, @path = @path, join_path
335
- if @depth_first then
340
+ def visit_depth
341
+ if @params.depth_first then
336
342
  enter_dir
337
- call_block or raise "#{self.class}: prune doesn't work with :depth_first."
343
+ call_block
338
344
  else
339
345
  call_block and enter_dir
340
346
  end
341
- @count += 1
342
- ensure
343
- @path = p_
344
- @levels.pop
345
347
  end
346
348
 
347
349
  def enter_dir
348
- return unless File.directory? @path
349
- if File.symlink? @path then
350
- return unless @follow and handle_error do
351
- d = @path.dup
352
- while d != Dir::CUR_DIR do
353
- d, = File.split d
354
- raise "cyclic recursion in #@path" if File.identical? d, @path
355
- end
356
- true
357
- end
358
- end
350
+ return unless @current.stat.directory? || (@params.follow &&
351
+ @current.symlink? && @current.rstat.directory?)
359
352
  handle_error do
360
- visit_dir @path
353
+ @current.cyclic? and
354
+ raise "Cyclic recursion in #{@current.path}"
355
+ visit_dir @current.path
361
356
  end
362
357
  end
363
358
 
364
- def visit_dir dir
365
- return if @max_depth and @max_depth == @depth
366
- list = (Dir.new dir).children
367
- @sort.call list
368
- list.each { |f| visit f }
369
- ensure
370
- end
371
-
372
359
  def call_block
373
- e = Entry.new @levels.last, @path, self
374
360
  handle_error do
375
- $_, $. = e.name, count
376
361
  begin
377
- e.instance_eval &@block
362
+ $_, $. = @current.name, @count
363
+ @current.instance_eval &@params.block
378
364
  rescue Done
379
365
  end
380
- if !(e.name.equal? @levels.last) && e.name != @levels.last then
381
- if e.name then
382
- e.name == (File.basename e.name) or
383
- raise "#{self.class}: rename to `#{e.name}' may not be a path."
384
- e.name.freeze
385
- @levels.pop
386
- @levels.push e.name
387
- p, @path = @path, join_path
388
- File.rename p, @path
389
- else
390
- if e.dir? then
391
- Dir.rmdir @path
392
- else
393
- File.unlink @path
394
- end
395
- end
396
- end
397
- true
366
+ @current.path
398
367
  end
399
368
  rescue Prune
400
369
  end
@@ -402,9 +371,9 @@ Sort without case sensitivity and preceding dot:
402
371
  def handle_error
403
372
  yield
404
373
  rescue
405
- case @error
406
- when Proc then @error.call
407
- when String then instance_eval @error
374
+ case @params.error
375
+ when Proc then @params.error.call
376
+ when String then instance_eval @params.error
408
377
  else raise
409
378
  end
410
379
  nil
@@ -417,21 +386,35 @@ Sort without case sensitivity and preceding dot:
417
386
 
418
387
  attr_reader :path, :name
419
388
 
420
- def initialize name, path, walk
421
- @name, @path, @walk = name, path, walk
389
+ def initialize filename, walk
390
+ @walk = walk
391
+ @prev, @name = walk.current, filename.dup.freeze
392
+ @path = join_path @name
393
+ end
394
+
395
+ protected
396
+ attr_reader :prev
397
+ private
398
+ def join_path name
399
+ @prev ? (File.join @prev.path, name).freeze : name
400
+ end
401
+ def reset
402
+ @fullpath = @stat = @rstat = @ostat = @colors = nil
422
403
  end
404
+ public
423
405
 
406
+ def count ; @walk.count ; end
424
407
  def depth ; @walk.depth ; end
425
408
  def now ; @walk.start ; end
426
409
 
427
- def fullpath ; @fullpath ||= File.absolute_path @path, @walk.wd ; end
410
+ def fullpath ; @fullpath ||= File.absolute_path @path ; end
428
411
 
429
412
  def stat ; @stat ||= File.lstat @path ; end
430
413
  def rstat ; @rstat ||= File.stat @path ; end
431
414
 
432
415
 
433
416
  private
434
- def append_slash s ; (File.directory? s) ? (File.join s, "") : s ; end
417
+ def append_slash s ; directory? ? (File.join s, "") : s ; end
435
418
  public
436
419
 
437
420
  def path! ; append_slash path ; end
@@ -461,7 +444,23 @@ Sort without case sensitivity and preceding dot:
461
444
  end
462
445
  public
463
446
 
464
- def dir? ; stat.directory? ; end
447
+ def directory? ; stat.directory? ; end
448
+ alias dir? directory?
449
+
450
+ def symlink? ; stat.symlink? ; end
451
+
452
+ def cyclic?
453
+ e = self
454
+ loop do
455
+ e = e.prev
456
+ e or break
457
+ if File.identical? e.path, @path then
458
+ return true
459
+ end
460
+ end
461
+ false
462
+ end
463
+
465
464
 
466
465
  def aage ; @walk.start - stat.atime ; end
467
466
  def mage ; @walk.start - stat.mtime ; end
@@ -516,10 +515,10 @@ Sort without case sensitivity and preceding dot:
516
515
  end
517
516
 
518
517
 
519
- def readlink ; File.readlink @path if stat.symlink? ; end
518
+ def readlink ; File.readlink @path if symlink? ; end
520
519
 
521
520
  def broken_link?
522
- return unless stat.symlink?
521
+ return unless symlink?
523
522
  rstat
524
523
  false
525
524
  rescue
@@ -529,7 +528,7 @@ Sort without case sensitivity and preceding dot:
529
528
 
530
529
  ARROW = " -> "
531
530
  def arrow
532
- ARROW + (File.readlink @path) if stat.symlink?
531
+ ARROW + (File.readlink @path) if symlink?
533
532
  end
534
533
 
535
534
 
@@ -552,7 +551,11 @@ Sort without case sensitivity and preceding dot:
552
551
  # Check whether a directory contains an entry.
553
552
  #
554
553
  def contains? name
555
- File.exists? File.join @path, name
554
+ p = File.join @path, name
555
+ File.lstat p
556
+ true
557
+ rescue
558
+ false
556
559
  end
557
560
 
558
561
  # :call-seq:
@@ -580,7 +583,8 @@ Sort without case sensitivity and preceding dot:
580
583
  # nothing will be done.
581
584
  #
582
585
  def open &block
583
- @ostat and @ostat.identical? @path and
586
+ @ostat ||= $stdout.stat
587
+ @ostat.identical? @path and
584
588
  raise "Refusing to open output file."
585
589
  File.open @path, &block if file?
586
590
  end
@@ -690,10 +694,27 @@ Sort without case sensitivity and preceding dot:
690
694
  include Csv
691
695
 
692
696
 
693
- def rename newname ; @name = newname ; end
697
+ def rename newname
698
+ @name = newname
699
+ newname == (File.basename newname) or
700
+ raise "Rename to `#{newname}' may not be a path."
701
+ p = join_path newname
702
+ (File.exist? p) and raise "Rename to `#{p}` would overwrite."
703
+ File.rename @path, p
704
+ @name, @path = newname.dup.freeze, p
705
+ reset
706
+ end
694
707
  alias mv rename
695
708
 
696
- def rm ; @name = nil ; end
709
+ def rm
710
+ if directory? then
711
+ Dir.rmdir @path
712
+ else
713
+ File.unlink @path
714
+ end
715
+ @name = @path = nil
716
+ reset
717
+ end
697
718
 
698
719
 
699
720
  def cname ; color name ; end
@@ -5,7 +5,7 @@
5
5
 
6
6
  =begin rdoc
7
7
 
8
- Human readable sizes, times, and modes.
8
+ Human readable sizes and times.
9
9
 
10
10
  Examples:
11
11
 
@@ -136,12 +136,23 @@ class Time
136
136
  # file.stat.mtime.lsish #=> " 1. Apr 2008 "
137
137
  #
138
138
  def lsish
139
- strftime "#{PERC_DAY}. %b " +
140
- (year == Time.now.year ? "%H:%M:%S" : "%Y ")
139
+ strftime "%e. %b " + (year == Time.start.year ? "%H:%M:%S" : "%Y ")
141
140
  end
142
141
 
143
- # Windows has no "%e".
144
- PERC_DAY = Time.now.strftime("%e") =~ /\d/ ? "%e" : "%d" # :nodoc:
142
+ def long
143
+ s = Time.start
144
+ if year == s.year && month == s.month && day == s.day then
145
+ strftime "==%H:%M:%S"
146
+ else
147
+ strftime "%Y-%m-%d"
148
+ end
149
+ end
150
+
151
+ class <<self
152
+ def start
153
+ @start ||= Time.now
154
+ end
155
+ end
145
156
 
146
157
  end
147
158
 
data/lib/rbfind/table.rb CHANGED
@@ -9,18 +9,28 @@ module RbFind
9
9
 
10
10
  def initialize *heads
11
11
  heads.flatten!
12
- @heads = heads
12
+ @heads = heads.map { |h|
13
+ a = case h
14
+ when />\z/ then +1
15
+ when /\^\z/ then 0
16
+ when /<?\z/ then -1
17
+ end
18
+ [ $`, a]
19
+ }
13
20
  @rows = []
14
21
  end
15
22
 
16
- def spawn
17
- self.class.new *@heads
23
+ attr_reader :heads
24
+ protected :heads
25
+ def initialize_copy oth
26
+ @heads = oth.heads
27
+ @rows = []
18
28
  end
19
29
 
20
30
  def add *row
21
31
  row.flatten!
22
32
  n = @heads.size
23
- row[ 0, n] = row[ 0, n].map { |r| r.to_s }
33
+ row.map! { |r| break if n.zero? ; n -= 1 ; r.to_s }
24
34
  @rows.push row
25
35
  end
26
36
 
@@ -32,20 +42,24 @@ module RbFind
32
42
  @rows.empty?
33
43
  end
34
44
 
35
- def output head: false
45
+ def output head: false, ifempty: nil
46
+ if empty? and ifempty then
47
+ puts ifempty
48
+ return
49
+ end
36
50
  make_lines head: head do |l| puts l end
37
51
  end
38
52
 
39
53
  def make_lines head: false
40
54
  rs = @rows
41
- rs.unshift heads_plain if head
55
+ rs.unshift @heads.map { |(h,a)| h } if head
42
56
  w = calc_widths
43
57
  rs.each { |r|
44
- j = (w.zip @heads, r).map { |v,h,c|
45
- case h
46
- when />\z/ then c.rjust v
47
- when /\^\z/ then c.center v
48
- when /<?\z/ then c.ljust v
58
+ j = (w.zip @heads, r).map { |v,(_,a),c|
59
+ case a
60
+ when -1 then c.ljust v
61
+ when 0 then c.center v
62
+ when +1 then c.rjust v
49
63
  end
50
64
  }
51
65
  l = j.join " "
@@ -59,14 +73,14 @@ module RbFind
59
73
  @html = ""
60
74
  tag :table, table, nl: 2 do
61
75
  tag :tr, row, nl: 1 do
62
- (@heads.zip heads_plain).each { |h,c|
63
- tag :td, c.downcase, align: (html_align h) do @html << c end
76
+ @heads.each { |(h,a)|
77
+ tag :td, h.downcase, align: a do @html << h end
64
78
  }
65
79
  end
66
80
  @rows.each { |r|
67
81
  tag :tr, table, nl: 1 do
68
- (@heads.zip heads_plain, r).each { |h,g,c|
69
- tag :td, g.downcase, align: (html_align h) do @html << c end
82
+ (@heads.zip r).each { |(g,a),c|
83
+ tag :td, g.downcase, align: a do @html << c end
70
84
  }
71
85
  end
72
86
  }
@@ -86,13 +100,9 @@ module RbFind
86
100
  w
87
101
  end
88
102
 
89
- def heads_plain
90
- @heads.map { |h| h.sub /\W\z/, "" }
91
- end
92
-
93
103
  def tag name, cls, nl: 0, align: nil
94
104
  @html << "<#{name}"
95
- @html << " style=\"text-align: " << align << ";\"" if align
105
+ @html << " style=\"text-align: " << (html_align align) << ";\"" if align
96
106
  @html << " class=\"" << cls << "\"" if cls
97
107
  @html << ">"
98
108
  @html << $/ if nl > 1
@@ -101,11 +111,11 @@ module RbFind
101
111
  @html << $/ if nl > 0
102
112
  end
103
113
 
104
- def html_align h
105
- case h
106
- when />/ then "right"
107
- when /\^/ then "center"
108
- when /<?/ then "left"
114
+ def html_align a
115
+ case a
116
+ when -1 then "left"
117
+ when 0 then "center"
118
+ when +1 then "right"
109
119
  end
110
120
  end
111
121
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbfind
3
3
  version: !ruby/object:Gem::Version
4
- version: '2.2'
4
+ version: '2.6'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bertram Scharpf
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-10-19 00:00:00.000000000 Z
11
+ date: 2021-03-04 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |
14
14
  A replacement for the standard UNIX command find.