tb 0.8 → 0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README +14 -7
- data/bin/tb +3 -3
- data/lib/tb.rb +3 -3
- data/lib/tb/basic.rb +34 -34
- data/lib/tb/catreader.rb +3 -3
- data/lib/tb/cmd_cat.rb +5 -5
- data/lib/tb/cmd_consecutive.rb +4 -4
- data/lib/tb/cmd_crop.rb +4 -4
- data/lib/tb/cmd_cross.rb +3 -3
- data/lib/tb/cmd_cut.rb +3 -3
- data/lib/tb/cmd_git.rb +3 -3
- data/lib/tb/cmd_grep.rb +3 -3
- data/lib/tb/cmd_group.rb +3 -3
- data/lib/tb/cmd_gsub.rb +3 -3
- data/lib/tb/cmd_help.rb +3 -3
- data/lib/tb/cmd_join.rb +3 -3
- data/lib/tb/cmd_ls.rb +3 -3
- data/lib/tb/cmd_melt.rb +3 -3
- data/lib/tb/cmd_mheader.rb +3 -3
- data/lib/tb/cmd_nest.rb +3 -3
- data/lib/tb/cmd_newfield.rb +17 -7
- data/lib/tb/cmd_rename.rb +3 -3
- data/lib/tb/cmd_shape.rb +3 -3
- data/lib/tb/cmd_sort.rb +3 -3
- data/lib/tb/cmd_svn.rb +3 -3
- data/lib/tb/cmd_tar.rb +3 -3
- data/lib/tb/cmd_to_csv.rb +4 -4
- data/lib/tb/cmd_to_json.rb +3 -3
- data/lib/tb/cmd_to_ltsv.rb +4 -4
- data/lib/tb/cmd_to_pnm.rb +3 -3
- data/lib/tb/cmd_to_pp.rb +3 -3
- data/lib/tb/cmd_to_tsv.rb +4 -4
- data/lib/tb/cmd_to_yaml.rb +3 -3
- data/lib/tb/cmd_unmelt.rb +3 -3
- data/lib/tb/cmd_unnest.rb +5 -4
- data/lib/tb/cmdmain.rb +3 -3
- data/lib/tb/cmdtop.rb +3 -3
- data/lib/tb/cmdutil.rb +3 -3
- data/lib/tb/csv.rb +10 -4
- data/lib/tb/customcmp.rb +3 -3
- data/lib/tb/customeq.rb +3 -3
- data/lib/tb/enumerable.rb +3 -3
- data/lib/tb/enumerator.rb +3 -3
- data/lib/tb/ex_enumerable.rb +2 -2
- data/lib/tb/ex_enumerator.rb +4 -4
- data/lib/tb/fieldset.rb +3 -3
- data/lib/tb/fileenumerator.rb +6 -6
- data/lib/tb/func.rb +3 -3
- data/lib/tb/json.rb +3 -3
- data/lib/tb/ltsv.rb +32 -7
- data/lib/tb/pnm.rb +3 -3
- data/lib/tb/reader.rb +3 -3
- data/lib/tb/record.rb +3 -3
- data/lib/tb/revcmp.rb +3 -3
- data/lib/tb/ropen.rb +23 -23
- data/lib/tb/search.rb +7 -7
- data/lib/tb/tsv.rb +3 -3
- data/lib/tb/zipper.rb +3 -3
- data/sample/excel2csv +36 -36
- data/sample/poi-xls2csv.rb +78 -78
- data/sample/poi-xls2csv.sh +3 -3
- data/sample/tbplot +214 -112
- data/test/test_basic.rb +4 -4
- data/test/test_cmd_newfield.rb +17 -3
- data/test/test_ex_enumerable.rb +18 -18
- data/test/test_ltsv.rb +8 -0
- metadata +5 -5
data/test/test_basic.rb
CHANGED
@@ -314,10 +314,10 @@ class TestTbBasic < Test::Unit::TestCase
|
|
314
314
|
end
|
315
315
|
|
316
316
|
def test_has_field?
|
317
|
-
t = Tb.new %w[fruit color],
|
318
|
-
%w[apple red],
|
319
|
-
%w[banana yellow],
|
320
|
-
%w[orange orange]
|
317
|
+
t = Tb.new %w[fruit color],
|
318
|
+
%w[apple red],
|
319
|
+
%w[banana yellow],
|
320
|
+
%w[orange orange]
|
321
321
|
assert_equal(true, t.has_field?("fruit"))
|
322
322
|
assert_equal(false, t.has_field?("foo"))
|
323
323
|
end
|
data/test/test_cmd_newfield.rb
CHANGED
@@ -21,7 +21,21 @@ class TestTbCmdNewfield < Test::Unit::TestCase
|
|
21
21
|
1,2
|
22
22
|
3,4
|
23
23
|
End
|
24
|
-
Tb::Cmd.main_newfield(['-o', o="o.csv", 'c', '
|
24
|
+
Tb::Cmd.main_newfield(['-o', o="o.csv", 'c', 'z', i])
|
25
|
+
assert_equal(<<-"End".gsub(/^[ \t]+/, ''), File.read(o))
|
26
|
+
c,a,b
|
27
|
+
z,1,2
|
28
|
+
z,3,4
|
29
|
+
End
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_rubyexp
|
33
|
+
File.open(i="i.csv", "w") {|f| f << <<-"End".gsub(/^[ \t]+/, '') }
|
34
|
+
a,b
|
35
|
+
1,2
|
36
|
+
3,4
|
37
|
+
End
|
38
|
+
Tb::Cmd.main_newfield(['-o', o="o.csv", 'c', '--ruby', '_["a"].to_i + _["b"].to_i', i])
|
25
39
|
assert_equal(<<-"End".gsub(/^[ \t]+/, ''), File.read(o))
|
26
40
|
c,a,b
|
27
41
|
3,1,2
|
@@ -34,7 +48,7 @@ class TestTbCmdNewfield < Test::Unit::TestCase
|
|
34
48
|
assert(!exc.success?)
|
35
49
|
end
|
36
50
|
|
37
|
-
def
|
51
|
+
def test_no_newfield_value
|
38
52
|
exc = assert_raise(SystemExit) { Tb::Cmd.main_newfield(['foo']) }
|
39
53
|
assert(!exc.success?)
|
40
54
|
end
|
@@ -50,7 +64,7 @@ class TestTbCmdNewfield < Test::Unit::TestCase
|
|
50
64
|
5,6
|
51
65
|
7,8
|
52
66
|
End
|
53
|
-
Tb::Cmd.main_newfield(['-o', o="o.csv", 'c', '_["a"].to_i - _["b"].to_i', i1, i2])
|
67
|
+
Tb::Cmd.main_newfield(['-o', o="o.csv", 'c', '--ruby', '_["a"].to_i - _["b"].to_i', i1, i2])
|
54
68
|
assert_equal(<<-"End".gsub(/^[ \t]+/, ''), File.read(o))
|
55
69
|
c,a,b
|
56
70
|
-1,1,2
|
data/test/test_ex_enumerable.rb
CHANGED
@@ -16,32 +16,32 @@ class TestTbEnumerable < Test::Unit::TestCase
|
|
16
16
|
a.tb_categorize(:taste, :color))
|
17
17
|
assert_equal({?n=>["banana", "melon"], ?e=>["grapefruit"]},
|
18
18
|
a.tb_categorize(lambda {|elt| elt[:fruit][4] }, :fruit))
|
19
|
-
|
19
|
+
|
20
20
|
assert_equal({"yellow"=>[true, true], "green"=>[true]},
|
21
21
|
a.tb_categorize(:color, lambda {|e| true }))
|
22
|
-
|
22
|
+
|
23
23
|
i = -1
|
24
24
|
assert_equal({"yellow"=>[0, 2], "green"=>[1]},
|
25
25
|
a.tb_categorize(:color, lambda {|e| i += 1 }))
|
26
|
-
|
26
|
+
|
27
27
|
assert_equal({"yellow"=>[{:fruit=>"banana", :color=>"yellow", :taste=>"sweet", :price=>100},
|
28
28
|
{:fruit=>"grapefruit", :color=>"yellow", :taste=>"tart", :price=>200}],
|
29
29
|
"green"=>[{:fruit=>"melon", :color=>"green", :taste=>"sweet", :price=>300}]},
|
30
30
|
a.tb_categorize(:color, lambda {|e| e }))
|
31
|
-
|
31
|
+
|
32
32
|
assert_equal({"yellow"=>[{:fruit=>"banana", :color=>"yellow", :taste=>"sweet", :price=>100},
|
33
33
|
{:fruit=>"grapefruit", :color=>"yellow", :taste=>"tart", :price=>200}],
|
34
34
|
"green"=>[{:fruit=>"melon", :color=>"green", :taste=>"sweet", :price=>300}]},
|
35
35
|
a.tb_categorize(:color, lambda {|e| e }))
|
36
|
-
|
36
|
+
|
37
37
|
i = -1
|
38
38
|
assert_equal({"yellow"=>[["banana", "sweet", 0], ["grapefruit", "tart", 2]],
|
39
39
|
"green"=>[["melon", "sweet", 1]]},
|
40
40
|
a.tb_categorize(:color, [:fruit, :taste, lambda {|e| i += 1 }]))
|
41
|
-
|
41
|
+
|
42
42
|
assert_equal({true=>["banana", "melon", "grapefruit"]},
|
43
43
|
a.tb_categorize(lambda {|e| true }, :fruit))
|
44
|
-
|
44
|
+
|
45
45
|
assert_equal({"yellow"=>2, "green"=>1},
|
46
46
|
a.tb_categorize(:color, lambda {|e| true }, :seed=>0, :op=>lambda {|s, v| s+1 }))
|
47
47
|
|
@@ -49,22 +49,22 @@ class TestTbEnumerable < Test::Unit::TestCase
|
|
49
49
|
:seed=>nil,
|
50
50
|
:op=>lambda {|s, v| s+1 },
|
51
51
|
:update=>lambda {|ks, s, v| s+1 }) }
|
52
|
-
|
52
|
+
|
53
53
|
assert_equal({"yellow"=>"bananagrapefruit", "green"=>"melon"},
|
54
54
|
a.tb_categorize(:color, :fruit, :seed=>"", :op=>:+))
|
55
55
|
|
56
56
|
assert_equal({"yellow"=>2, "green"=>1},
|
57
57
|
a.tb_categorize(:color, lambda {|e| 1 }, :op=>:+))
|
58
|
-
|
58
|
+
|
59
59
|
assert_equal({"yellow"=>"banana,grapefruit", "green"=>"melon"},
|
60
60
|
a.tb_categorize(:color, :fruit) {|ks, vs| vs.join(",") } )
|
61
|
-
|
61
|
+
|
62
62
|
assert_equal({"yellow"=>150.0, "green"=>300.0},
|
63
63
|
a.tb_categorize(:color, :price) {|ks, vs| vs.inject(0.0, &:+) / vs.length })
|
64
64
|
|
65
65
|
assert_equal({"yellow"=>{"banana"=>100.0, "grapefruit"=>200.0}, "green"=>{"melon"=>300.0}},
|
66
66
|
a.tb_categorize(:color, :fruit, :price) {|ks, vs| vs.inject(0.0, &:+) / vs.length })
|
67
|
-
|
67
|
+
|
68
68
|
assert_raise(ArgumentError) { a.tb_categorize('a') }
|
69
69
|
end
|
70
70
|
|
@@ -95,12 +95,12 @@ class TestTbEnumerable < Test::Unit::TestCase
|
|
95
95
|
{:fruit => "grapefruit", :color => "yellow", :taste => "tart", :price => 200}]
|
96
96
|
assert_equal({"banana"=>100, "melon"=>300, "grapefruit"=>200},
|
97
97
|
a.tb_unique_categorize(:fruit, :price))
|
98
|
-
|
98
|
+
|
99
99
|
assert_raise(ArgumentError) { a.tb_unique_categorize(:color, :price) }
|
100
|
-
|
100
|
+
|
101
101
|
assert_equal({"sweet"=>400, "tart"=>200},
|
102
102
|
a.tb_unique_categorize(:taste, :price) {|s, v| !s ? v : s + v })
|
103
|
-
|
103
|
+
|
104
104
|
assert_equal({"yellow"=>300, "green"=>300},
|
105
105
|
a.tb_unique_categorize(:color, :price, :seed=>0) {|s, v| s + v })
|
106
106
|
end
|
@@ -109,13 +109,13 @@ class TestTbEnumerable < Test::Unit::TestCase
|
|
109
109
|
a = [{:fruit => "banana", :color => "yellow", :taste => "sweet", :price => 100},
|
110
110
|
{:fruit => "melon", :color => "green", :taste => "sweet", :price => 300},
|
111
111
|
{:fruit => "grapefruit", :color => "yellow", :taste => "tart", :price => 200}]
|
112
|
-
|
112
|
+
|
113
113
|
assert_equal({"yellow"=>2, "green"=>1},
|
114
114
|
a.tb_category_count(:color))
|
115
|
-
|
115
|
+
|
116
116
|
assert_equal({"sweet"=>2, "tart"=>1},
|
117
117
|
a.tb_category_count(:taste))
|
118
|
-
|
118
|
+
|
119
119
|
assert_equal({"sweet"=>{"yellow"=>1, "green"=>1}, "tart"=>{"yellow"=>1}},
|
120
120
|
a.tb_category_count(:taste, :color))
|
121
121
|
end
|
@@ -328,7 +328,7 @@ class TestTbEnumerable < Test::Unit::TestCase
|
|
328
328
|
[].detect_nested_group_by(
|
329
329
|
[[lambda {|v| v.even? },
|
330
330
|
lambda {|v| result << [:s, v] },
|
331
|
-
lambda {|v| result << [:e, v] }]]).each {|v| result << v }
|
331
|
+
lambda {|v| result << [:e, v] }]]).each {|v| result << v }
|
332
332
|
assert_equal([], result)
|
333
333
|
end
|
334
334
|
|
data/test/test_ltsv.rb
CHANGED
@@ -2,6 +2,14 @@ require 'tb'
|
|
2
2
|
require 'test/unit'
|
3
3
|
|
4
4
|
class TestTbLTSV < Test::Unit::TestCase
|
5
|
+
def test_escape_and_unescape
|
6
|
+
0x00.upto(0x7f) {|c|
|
7
|
+
s = [c].pack("C")
|
8
|
+
assert_equal(s, Tb.ltsv_unescape_string(Tb.ltsv_escape_key(s)))
|
9
|
+
assert_equal(s, Tb.ltsv_unescape_string(Tb.ltsv_escape_value(s)))
|
10
|
+
}
|
11
|
+
end
|
12
|
+
|
5
13
|
def test_parse
|
6
14
|
r = Tb::LTSVReader.new("a:1\tb:2\na:3\tb:4\n")
|
7
15
|
result = []
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.9'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tanaka Akira
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-04-29 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |
|
14
14
|
tb is a manipulation tool for table: CSV, TSV, LTSV, JSON, etc.
|
@@ -153,17 +153,17 @@ require_paths:
|
|
153
153
|
- lib
|
154
154
|
required_ruby_version: !ruby/object:Gem::Requirement
|
155
155
|
requirements:
|
156
|
-
- -
|
156
|
+
- - ">="
|
157
157
|
- !ruby/object:Gem::Version
|
158
158
|
version: 1.9.2
|
159
159
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
160
160
|
requirements:
|
161
|
-
- -
|
161
|
+
- - ">="
|
162
162
|
- !ruby/object:Gem::Version
|
163
163
|
version: '0'
|
164
164
|
requirements: []
|
165
165
|
rubyforge_project:
|
166
|
-
rubygems_version: 2.
|
166
|
+
rubygems_version: 2.2.2
|
167
167
|
signing_key:
|
168
168
|
specification_version: 4
|
169
169
|
summary: 'manipulation tool for tables: CSV, TSV, LTSV, JSON, etc.'
|