rbfind 1.11 → 2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,82 @@
1
+ #
2
+ # rbfind/core.rb -- Additional core functions
3
+ #
4
+
5
+
6
+ class Dir
7
+
8
+ SPECIAL_DIRS = %w(. ..)
9
+ CUR_DIR, SUPER_DIR = *SPECIAL_DIRS
10
+
11
+ method_defined? :each_child or def each_child
12
+ s = SPECIAL_DIRS.dup
13
+ each { |f|
14
+ next if s.delete f
15
+ yield f
16
+ }
17
+ end
18
+
19
+ method_defined? :children or def children
20
+ entries - SPECIAL_DIRS
21
+ end
22
+
23
+ end
24
+
25
+
26
+ class File
27
+
28
+ class Stat
29
+
30
+ def identical? oth
31
+ oth = self.class.new oth unless self.class === oth
32
+ dev == oth.dev and ino == oth.ino
33
+ end
34
+
35
+ def stype
36
+ case mode >> 12
37
+ when 001 then "p"
38
+ when 002 then "c"
39
+ when 004 then "d"
40
+ when 006 then "b"
41
+ when 010 then "-"
42
+ when 012 then "l"
43
+ when 014 then "s"
44
+ when 016 then "w"
45
+ else "?"
46
+ end
47
+ end
48
+
49
+ def suffix
50
+ case mode >> 12
51
+ when 001 then "|"
52
+ when 002 then " "
53
+ when 004 then "/"
54
+ when 006 then " "
55
+ when 010 then executable? ? "*" : " "
56
+ when 012 then "@"
57
+ when 014 then "="
58
+ when 016 then "%"
59
+ else "?"
60
+ end
61
+ end
62
+
63
+ def modes
64
+ r = ""
65
+ m = mode
66
+ 3.times {
67
+ r.insert 0, ((m & 01).nonzero? ? "x" : "-")
68
+ r.insert 0, ((m & 02).nonzero? ? "w" : "-")
69
+ r.insert 0, ((m & 04).nonzero? ? "r" : "-")
70
+ m >>= 3
71
+ }
72
+ (m & 04).nonzero? and r[ 2] = r[ 2] == "x" ? "s" : "S"
73
+ (m & 02).nonzero? and r[ 5] = r[ 5] == "x" ? "s" : "S"
74
+ (m & 01).nonzero? and r[ 8] = r[ 8] == "x" ? "t" : "T"
75
+ r
76
+ end
77
+
78
+ end
79
+
80
+ end
81
+
82
+
@@ -0,0 +1,54 @@
1
+ #
2
+ # rbfind/csv.rb -- Write CSV-like output
3
+ #
4
+
5
+
6
+ module RbFind
7
+
8
+ module Csv
9
+
10
+ # Windows has ":" in filenames ("C:\...")
11
+ COLON = File::ALT_SEPARATOR ? "|" : ":" # :nodoc:
12
+
13
+ def colsep *args
14
+ csv COLON, *args
15
+ end
16
+ alias col_sep colsep
17
+
18
+ def tabsep *args
19
+ csv "\t", *args
20
+ end
21
+ alias tab_sep tabsep
22
+
23
+ def spcsep *args
24
+ csv " ", *args
25
+ end
26
+ alias spc_sep spcsep
27
+ alias space_sep spc_sep
28
+ alias spacesep spcsep
29
+ alias p spcsep
30
+
31
+ def csv sep, *args
32
+ e = args.join sep
33
+ Csv.putl e
34
+ end
35
+
36
+
37
+ @outfile = $stdout
38
+
39
+ class <<self
40
+ def putl l
41
+ @outfile << l << $/
42
+ end
43
+ def outfile out
44
+ o, @outfile = @outfile, out
45
+ yield
46
+ ensure
47
+ @outfile = o
48
+ end
49
+ end
50
+
51
+ end
52
+
53
+ end
54
+
@@ -1,7 +1,7 @@
1
1
  #
2
- # humansiz.rb -- human readable sizes
2
+ # humansiz.rb -- Numeric class extensions for human readable sizes
3
3
  #
4
- # Numeric class extensions for human readable sizes.
4
+
5
5
 
6
6
  =begin rdoc
7
7
 
@@ -20,6 +20,7 @@ Examples:
20
20
 
21
21
  =end
22
22
 
23
+
23
24
  class Numeric # sizes in bytes
24
25
 
25
26
  # :stopdoc:
@@ -82,18 +83,38 @@ class Numeric # sizes in bytes
82
83
  end
83
84
 
84
85
 
85
- class Numeric # time values
86
- def s ; self ; end
87
- def m ; s * 60 ; end
88
- def h ; m * 60 ; end
89
- def d ; h * 24 ; end
90
- def w ; d * 7 ; end
86
+ class Numeric
87
+ "smhdw".each_char { |c|
88
+ define_method c do Time.to_sec self, c end
89
+ }
90
+ def t ; Time.to_unit to_i ; end
91
91
  end
92
92
 
93
93
 
94
-
95
94
  class Time
96
95
 
96
+ TIME_UNITS = [ "seconds", 60, "minutes", 60, "hours", 24, "days", 7, "weeks", ]
97
+ class <<self
98
+ def to_unit n
99
+ u = TIME_UNITS.each_slice 2 do |nam,val|
100
+ break nam if not val or n < val
101
+ n /= val
102
+ end
103
+ "#{n}#{u[0]}"
104
+ end
105
+ def to_sec num, unit
106
+ TIME_UNITS.each_slice 2 do |nam,val|
107
+ return num if nam.start_with? unit
108
+ num *= val
109
+ end
110
+ raise "No time unit: #{unit}."
111
+ end
112
+ def str_to_sec str
113
+ str =~ /(\d*) *(\w*)/
114
+ to_sec $1.to_i, $2
115
+ end
116
+ end
117
+
97
118
  # :call-seq:
98
119
  # time.lsish() -> str
99
120
  #
@@ -0,0 +1,114 @@
1
+ #
2
+ # rbfind/table.rb -- Table for data
3
+ #
4
+
5
+
6
+ module RbFind
7
+
8
+ class Table
9
+
10
+ def initialize *heads
11
+ heads.flatten!
12
+ @heads = heads
13
+ @rows = []
14
+ end
15
+
16
+ def spawn
17
+ self.class.new *@heads
18
+ end
19
+
20
+ def add *row
21
+ row.flatten!
22
+ n = @heads.size
23
+ row[ 0, n] = row[ 0, n].map { |r| r.to_s }
24
+ @rows.push row
25
+ end
26
+
27
+ def sort_by! *nums
28
+ @rows.sort_by! { |x| nums.map { |i| x[i] } }
29
+ end
30
+
31
+ def empty?
32
+ @rows.empty?
33
+ end
34
+
35
+ def output head: false
36
+ make_lines head: head do |l| puts l end
37
+ end
38
+
39
+ def make_lines head: false
40
+ rs = @rows
41
+ rs.unshift heads_plain if head
42
+ w = calc_widths
43
+ 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
49
+ end
50
+ }
51
+ l = j.join " "
52
+ l.rstrip!
53
+ yield l
54
+ }
55
+ nil
56
+ end
57
+
58
+ def make_html table: nil, row: nil
59
+ @html = ""
60
+ tag :table, table, nl: 2 do
61
+ 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
64
+ }
65
+ end
66
+ @rows.each { |r|
67
+ 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
70
+ }
71
+ end
72
+ }
73
+ end
74
+ @html
75
+ ensure
76
+ @html = nil
77
+ end
78
+
79
+ private
80
+
81
+ def calc_widths
82
+ w = @heads.map { 0 }
83
+ @rows.each { |r|
84
+ w = (w.zip r).map { |i,c| j = c.length ; j > i ? j : i }
85
+ }
86
+ w
87
+ end
88
+
89
+ def heads_plain
90
+ @heads.map { |h| h.sub /\W\z/, "" }
91
+ end
92
+
93
+ def tag name, cls, nl: 0, align: nil
94
+ @html << "<#{name}"
95
+ @html << " style=\"text-align: " << align << ";\"" if align
96
+ @html << " class=\"" << cls << "\"" if cls
97
+ @html << ">"
98
+ @html << $/ if nl > 1
99
+ yield
100
+ @html << "</#{name}>"
101
+ @html << $/ if nl > 0
102
+ end
103
+
104
+ def html_align h
105
+ case h
106
+ when />/ then "right"
107
+ when /\^/ then "center"
108
+ when /<?/ then "left"
109
+ end
110
+ end
111
+
112
+ end
113
+
114
+ end
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: '1.11'
4
+ version: '2.1'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bertram Scharpf
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-06-07 00:00:00.000000000 Z
11
+ date: 2020-07-20 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |
14
14
  A replacement for the standard UNIX command find.
@@ -25,13 +25,16 @@ files:
25
25
  - LICENSE
26
26
  - README
27
27
  - bin/rbfind
28
- - lib/humansiz.rb
29
28
  - lib/rbfind.rb
29
+ - lib/rbfind/core.rb
30
+ - lib/rbfind/csv.rb
31
+ - lib/rbfind/humansiz.rb
32
+ - lib/rbfind/table.rb
30
33
  homepage: http://www.bertram-scharpf.de/software/rbfind
31
34
  licenses:
32
35
  - BSD-2-Clause
33
36
  metadata: {}
34
- post_install_message:
37
+ post_install_message:
35
38
  rdoc_options:
36
39
  - "--charset"
37
40
  - utf-8
@@ -51,8 +54,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
51
54
  version: '0'
52
55
  requirements:
53
56
  - just Ruby
54
- rubygems_version: 3.0.3
55
- signing_key:
57
+ rubygems_version: 3.0.6
58
+ signing_key:
56
59
  specification_version: 4
57
60
  summary: Ruby replacement for the standard Unix find tool
58
61
  test_files: []