tb 0.1 → 0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README +156 -5
- data/bin/tb +2 -1110
- data/lib/tb.rb +4 -2
- data/lib/tb/catreader.rb +131 -0
- data/lib/tb/cmd_cat.rb +65 -0
- data/lib/tb/cmd_consecutive.rb +79 -0
- data/lib/tb/cmd_crop.rb +105 -0
- data/lib/tb/cmd_cross.rb +119 -0
- data/lib/tb/cmd_csv.rb +42 -0
- data/lib/tb/cmd_cut.rb +77 -0
- data/lib/tb/cmd_grep.rb +76 -0
- data/lib/tb/cmd_group.rb +82 -0
- data/lib/tb/cmd_gsub.rb +77 -0
- data/lib/tb/cmd_help.rb +98 -0
- data/lib/tb/cmd_join.rb +81 -0
- data/lib/tb/cmd_json.rb +60 -0
- data/lib/tb/cmd_ls.rb +273 -0
- data/lib/tb/cmd_mheader.rb +77 -0
- data/lib/tb/cmd_newfield.rb +59 -0
- data/lib/tb/cmd_pnm.rb +43 -0
- data/lib/tb/cmd_pp.rb +70 -0
- data/lib/tb/cmd_rename.rb +58 -0
- data/lib/tb/cmd_shape.rb +67 -0
- data/lib/tb/cmd_sort.rb +58 -0
- data/lib/tb/cmd_svn_log.rb +158 -0
- data/lib/tb/cmd_tsv.rb +43 -0
- data/lib/tb/cmd_yaml.rb +47 -0
- data/lib/tb/cmdmain.rb +45 -0
- data/lib/tb/cmdtop.rb +58 -0
- data/lib/tb/cmdutil.rb +327 -0
- data/lib/tb/csv.rb +30 -6
- data/lib/tb/fieldset.rb +39 -41
- data/lib/tb/pager.rb +132 -0
- data/lib/tb/pnm.rb +357 -0
- data/lib/tb/reader.rb +18 -128
- data/lib/tb/record.rb +3 -3
- data/lib/tb/ropen.rb +70 -0
- data/lib/tb/{pathfinder.rb → search.rb} +69 -34
- data/lib/tb/tsv.rb +29 -1
- data/sample/colors.ppm +0 -0
- data/sample/gradation.pgm +0 -0
- data/sample/langs.csv +46 -0
- data/sample/tbplot +293 -0
- data/test-all-cov.rb +65 -0
- data/test-all.rb +5 -0
- data/test/test_basic.rb +99 -2
- data/test/test_catreader.rb +27 -0
- data/test/test_cmd_cat.rb +118 -0
- data/test/test_cmd_consecutive.rb +90 -0
- data/test/test_cmd_crop.rb +101 -0
- data/test/test_cmd_cross.rb +113 -0
- data/test/test_cmd_csv.rb +129 -0
- data/test/test_cmd_cut.rb +100 -0
- data/test/test_cmd_grep.rb +89 -0
- data/test/test_cmd_group.rb +181 -0
- data/test/test_cmd_gsub.rb +103 -0
- data/test/test_cmd_help.rb +190 -0
- data/test/test_cmd_join.rb +197 -0
- data/test/test_cmd_json.rb +75 -0
- data/test/test_cmd_ls.rb +203 -0
- data/test/test_cmd_mheader.rb +86 -0
- data/test/test_cmd_newfield.rb +63 -0
- data/test/test_cmd_pnm.rb +35 -0
- data/test/test_cmd_pp.rb +62 -0
- data/test/test_cmd_rename.rb +91 -0
- data/test/test_cmd_shape.rb +50 -0
- data/test/test_cmd_sort.rb +105 -0
- data/test/test_cmd_tsv.rb +67 -0
- data/test/test_cmd_yaml.rb +55 -0
- data/test/test_cmdtty.rb +154 -0
- data/test/test_cmdutil.rb +43 -0
- data/test/test_csv.rb +10 -0
- data/test/test_fieldset.rb +42 -0
- data/test/test_pager.rb +142 -0
- data/test/test_pnm.rb +374 -0
- data/test/test_reader.rb +147 -0
- data/test/test_record.rb +49 -0
- data/test/test_search.rb +575 -0
- data/test/test_tsv.rb +7 -0
- metadata +108 -5
- data/lib/tb/qtsv.rb +0 -93
data/test/test_tsv.rb
CHANGED
@@ -38,4 +38,11 @@ class TestTbTSV < Test::Unit::TestCase
|
|
38
38
|
tbl.generate_tsv(out="")
|
39
39
|
assert_equal("a\tb\nfoo\tbar\n", out)
|
40
40
|
end
|
41
|
+
|
42
|
+
def test_generate_tsv_with_block
|
43
|
+
tbl = Tb.new %w[a b], %w[foo bar], %w[q w]
|
44
|
+
tbl.generate_tsv(out="") {|recids| recids.reverse }
|
45
|
+
assert_equal("a\tb\nq\tw\nfoo\tbar\n", out)
|
46
|
+
end
|
47
|
+
|
41
48
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.2'
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,9 +9,18 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-12-
|
12
|
+
date: 2011-12-29 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
|
-
description: ! 'manipulation tool for table: CSV, TSV, etc.
|
14
|
+
description: ! 'tb is a manipulation tool for table: CSV, TSV, etc.
|
15
|
+
|
16
|
+
|
17
|
+
tb provides a command and a library for manipulating tables:
|
18
|
+
|
19
|
+
Unix filter like operations (grep, sort, cat, cut, ls, etc.),
|
20
|
+
|
21
|
+
SQL like operations (join, group, etc.),
|
22
|
+
|
23
|
+
and more.
|
15
24
|
|
16
25
|
'
|
17
26
|
email: akr@fsij.org
|
@@ -24,22 +33,86 @@ files:
|
|
24
33
|
- bin/tb
|
25
34
|
- lib/tb.rb
|
26
35
|
- lib/tb/basic.rb
|
36
|
+
- lib/tb/catreader.rb
|
37
|
+
- lib/tb/cmd_cat.rb
|
38
|
+
- lib/tb/cmd_consecutive.rb
|
39
|
+
- lib/tb/cmd_crop.rb
|
40
|
+
- lib/tb/cmd_cross.rb
|
41
|
+
- lib/tb/cmd_csv.rb
|
42
|
+
- lib/tb/cmd_cut.rb
|
43
|
+
- lib/tb/cmd_grep.rb
|
44
|
+
- lib/tb/cmd_group.rb
|
45
|
+
- lib/tb/cmd_gsub.rb
|
46
|
+
- lib/tb/cmd_help.rb
|
47
|
+
- lib/tb/cmd_join.rb
|
48
|
+
- lib/tb/cmd_json.rb
|
49
|
+
- lib/tb/cmd_ls.rb
|
50
|
+
- lib/tb/cmd_mheader.rb
|
51
|
+
- lib/tb/cmd_newfield.rb
|
52
|
+
- lib/tb/cmd_pnm.rb
|
53
|
+
- lib/tb/cmd_pp.rb
|
54
|
+
- lib/tb/cmd_rename.rb
|
55
|
+
- lib/tb/cmd_shape.rb
|
56
|
+
- lib/tb/cmd_sort.rb
|
57
|
+
- lib/tb/cmd_svn_log.rb
|
58
|
+
- lib/tb/cmd_tsv.rb
|
59
|
+
- lib/tb/cmd_yaml.rb
|
60
|
+
- lib/tb/cmdmain.rb
|
61
|
+
- lib/tb/cmdtop.rb
|
62
|
+
- lib/tb/cmdutil.rb
|
27
63
|
- lib/tb/csv.rb
|
28
64
|
- lib/tb/enumerable.rb
|
29
65
|
- lib/tb/fieldset.rb
|
30
|
-
- lib/tb/
|
31
|
-
- lib/tb/
|
66
|
+
- lib/tb/pager.rb
|
67
|
+
- lib/tb/pnm.rb
|
32
68
|
- lib/tb/reader.rb
|
33
69
|
- lib/tb/record.rb
|
70
|
+
- lib/tb/ropen.rb
|
71
|
+
- lib/tb/search.rb
|
34
72
|
- lib/tb/tsv.rb
|
73
|
+
- sample/colors.ppm
|
35
74
|
- sample/excel2csv
|
75
|
+
- sample/gradation.pgm
|
76
|
+
- sample/langs.csv
|
36
77
|
- sample/poi-xls2csv.rb
|
37
78
|
- sample/poi-xls2csv.sh
|
79
|
+
- sample/tbplot
|
80
|
+
- test-all-cov.rb
|
38
81
|
- test-all.rb
|
39
82
|
- test/test_basic.rb
|
83
|
+
- test/test_catreader.rb
|
84
|
+
- test/test_cmd_cat.rb
|
85
|
+
- test/test_cmd_consecutive.rb
|
86
|
+
- test/test_cmd_crop.rb
|
87
|
+
- test/test_cmd_cross.rb
|
88
|
+
- test/test_cmd_csv.rb
|
89
|
+
- test/test_cmd_cut.rb
|
90
|
+
- test/test_cmd_grep.rb
|
91
|
+
- test/test_cmd_group.rb
|
92
|
+
- test/test_cmd_gsub.rb
|
93
|
+
- test/test_cmd_help.rb
|
94
|
+
- test/test_cmd_join.rb
|
95
|
+
- test/test_cmd_json.rb
|
96
|
+
- test/test_cmd_ls.rb
|
97
|
+
- test/test_cmd_mheader.rb
|
98
|
+
- test/test_cmd_newfield.rb
|
99
|
+
- test/test_cmd_pnm.rb
|
100
|
+
- test/test_cmd_pp.rb
|
101
|
+
- test/test_cmd_rename.rb
|
102
|
+
- test/test_cmd_shape.rb
|
103
|
+
- test/test_cmd_sort.rb
|
104
|
+
- test/test_cmd_tsv.rb
|
105
|
+
- test/test_cmd_yaml.rb
|
106
|
+
- test/test_cmdtty.rb
|
107
|
+
- test/test_cmdutil.rb
|
40
108
|
- test/test_csv.rb
|
41
109
|
- test/test_enumerable.rb
|
110
|
+
- test/test_fieldset.rb
|
111
|
+
- test/test_pager.rb
|
112
|
+
- test/test_pnm.rb
|
113
|
+
- test/test_reader.rb
|
42
114
|
- test/test_record.rb
|
115
|
+
- test/test_search.rb
|
43
116
|
- test/test_tsv.rb
|
44
117
|
homepage: https://github.com/akr/tb
|
45
118
|
licenses: []
|
@@ -67,7 +140,37 @@ specification_version: 3
|
|
67
140
|
summary: ! 'manipulation tool for table: CSV, TSV, etc.'
|
68
141
|
test_files:
|
69
142
|
- test/test_basic.rb
|
143
|
+
- test/test_catreader.rb
|
144
|
+
- test/test_cmd_cat.rb
|
145
|
+
- test/test_cmd_consecutive.rb
|
146
|
+
- test/test_cmd_crop.rb
|
147
|
+
- test/test_cmd_cross.rb
|
148
|
+
- test/test_cmd_csv.rb
|
149
|
+
- test/test_cmd_cut.rb
|
150
|
+
- test/test_cmd_grep.rb
|
151
|
+
- test/test_cmd_group.rb
|
152
|
+
- test/test_cmd_gsub.rb
|
153
|
+
- test/test_cmd_help.rb
|
154
|
+
- test/test_cmd_join.rb
|
155
|
+
- test/test_cmd_json.rb
|
156
|
+
- test/test_cmd_ls.rb
|
157
|
+
- test/test_cmd_mheader.rb
|
158
|
+
- test/test_cmd_newfield.rb
|
159
|
+
- test/test_cmd_pnm.rb
|
160
|
+
- test/test_cmd_pp.rb
|
161
|
+
- test/test_cmd_rename.rb
|
162
|
+
- test/test_cmd_shape.rb
|
163
|
+
- test/test_cmd_sort.rb
|
164
|
+
- test/test_cmd_tsv.rb
|
165
|
+
- test/test_cmd_yaml.rb
|
166
|
+
- test/test_cmdtty.rb
|
167
|
+
- test/test_cmdutil.rb
|
70
168
|
- test/test_csv.rb
|
71
169
|
- test/test_enumerable.rb
|
170
|
+
- test/test_fieldset.rb
|
171
|
+
- test/test_pager.rb
|
172
|
+
- test/test_pnm.rb
|
173
|
+
- test/test_reader.rb
|
72
174
|
- test/test_record.rb
|
175
|
+
- test/test_search.rb
|
73
176
|
- test/test_tsv.rb
|
data/lib/tb/qtsv.rb
DELETED
@@ -1,93 +0,0 @@
|
|
1
|
-
# lib/tb/qtsv.rb - quoted TSV related fetures for table library
|
2
|
-
#
|
3
|
-
# Copyright (C) 2010 Tanaka Akira <akr@fsij.org>
|
4
|
-
#
|
5
|
-
# Redistribution and use in source and binary forms, with or without
|
6
|
-
# modification, are permitted provided that the following conditions are met:
|
7
|
-
#
|
8
|
-
# 1. Redistributions of source code must retain the above copyright notice, this
|
9
|
-
# list of conditions and the following disclaimer.
|
10
|
-
# 2. Redistributions in binary form must reproduce the above copyright notice,
|
11
|
-
# this list of conditions and the following disclaimer in the documentation
|
12
|
-
# and/or other materials provided with the distribution.
|
13
|
-
# 3. The name of the author may not be used to endorse or promote products
|
14
|
-
# derived from this software without specific prior written permission.
|
15
|
-
#
|
16
|
-
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
17
|
-
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
18
|
-
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
19
|
-
# EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
20
|
-
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
21
|
-
# OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
22
|
-
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
23
|
-
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
24
|
-
# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
|
25
|
-
# OF SUCH DAMAGE.
|
26
|
-
|
27
|
-
class Tb
|
28
|
-
|
29
|
-
# quoted TSV is a variant of TSV (tab separated value)
|
30
|
-
#
|
31
|
-
# All non-empty values are quoted by double-quotes.
|
32
|
-
|
33
|
-
def Tb.load_qtsv(filename, *header_fields, &block)
|
34
|
-
Tb.parse_qtsv(File.read(filename), *header_fields, &block)
|
35
|
-
end
|
36
|
-
|
37
|
-
def Tb.qtsv_stream_input(qtsv)
|
38
|
-
qtsv = qtsv.read unless String === qtsv
|
39
|
-
qtsv = qtsv.dup
|
40
|
-
cells = []
|
41
|
-
verify = ''
|
42
|
-
qtsv.scan(/\G("(.*?)"|)(\t|\n|\r\n|\z)/m) {
|
43
|
-
verify << $&
|
44
|
-
cell = $2
|
45
|
-
sep = $3
|
46
|
-
break if cell.nil? && sep.empty?
|
47
|
-
cells << cell
|
48
|
-
if sep != "\t"
|
49
|
-
yield cells
|
50
|
-
cells = []
|
51
|
-
end
|
52
|
-
}
|
53
|
-
if verify != qtsv
|
54
|
-
if qtsv.start_with?(verify)
|
55
|
-
raise "unexpected scan ('verify' is a prefix of 'qtsv')"
|
56
|
-
end
|
57
|
-
if verify.length != qtsv.length
|
58
|
-
raise "unexpected scan (length differ: orig:#{qtsv.length} verify:#{verify.length})"
|
59
|
-
end
|
60
|
-
raise "unexpected scan"
|
61
|
-
end
|
62
|
-
nil
|
63
|
-
end
|
64
|
-
|
65
|
-
def Tb.parse_qtsv(qtsv, *header_fields)
|
66
|
-
aa = []
|
67
|
-
qtsv_stream_input(qtsv) {|ary|
|
68
|
-
aa << ary
|
69
|
-
}
|
70
|
-
aa = yield aa if block_given?
|
71
|
-
if header_fields.empty?
|
72
|
-
aa.shift while aa.first.all? {|elt| elt.nil? || elt == '' }
|
73
|
-
header_fields = aa.shift
|
74
|
-
h = Hash.new(0)
|
75
|
-
header_fields.each_with_index {|f, i|
|
76
|
-
if h.include? f
|
77
|
-
raise ArgumentError, "ambiguous header field: #{f.inspect} (#{h[f]}th and #{i}th)"
|
78
|
-
end
|
79
|
-
h[f] = i
|
80
|
-
}
|
81
|
-
end
|
82
|
-
t = Tb.new(header_fields)
|
83
|
-
aa.each {|ary|
|
84
|
-
h = {}
|
85
|
-
header_fields.each_with_index {|f, i|
|
86
|
-
h[f] = ary[i]
|
87
|
-
}
|
88
|
-
t.insert(h)
|
89
|
-
}
|
90
|
-
t
|
91
|
-
end
|
92
|
-
|
93
|
-
end
|