tb 0.8 → 0.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/README +14 -7
  3. data/bin/tb +3 -3
  4. data/lib/tb.rb +3 -3
  5. data/lib/tb/basic.rb +34 -34
  6. data/lib/tb/catreader.rb +3 -3
  7. data/lib/tb/cmd_cat.rb +5 -5
  8. data/lib/tb/cmd_consecutive.rb +4 -4
  9. data/lib/tb/cmd_crop.rb +4 -4
  10. data/lib/tb/cmd_cross.rb +3 -3
  11. data/lib/tb/cmd_cut.rb +3 -3
  12. data/lib/tb/cmd_git.rb +3 -3
  13. data/lib/tb/cmd_grep.rb +3 -3
  14. data/lib/tb/cmd_group.rb +3 -3
  15. data/lib/tb/cmd_gsub.rb +3 -3
  16. data/lib/tb/cmd_help.rb +3 -3
  17. data/lib/tb/cmd_join.rb +3 -3
  18. data/lib/tb/cmd_ls.rb +3 -3
  19. data/lib/tb/cmd_melt.rb +3 -3
  20. data/lib/tb/cmd_mheader.rb +3 -3
  21. data/lib/tb/cmd_nest.rb +3 -3
  22. data/lib/tb/cmd_newfield.rb +17 -7
  23. data/lib/tb/cmd_rename.rb +3 -3
  24. data/lib/tb/cmd_shape.rb +3 -3
  25. data/lib/tb/cmd_sort.rb +3 -3
  26. data/lib/tb/cmd_svn.rb +3 -3
  27. data/lib/tb/cmd_tar.rb +3 -3
  28. data/lib/tb/cmd_to_csv.rb +4 -4
  29. data/lib/tb/cmd_to_json.rb +3 -3
  30. data/lib/tb/cmd_to_ltsv.rb +4 -4
  31. data/lib/tb/cmd_to_pnm.rb +3 -3
  32. data/lib/tb/cmd_to_pp.rb +3 -3
  33. data/lib/tb/cmd_to_tsv.rb +4 -4
  34. data/lib/tb/cmd_to_yaml.rb +3 -3
  35. data/lib/tb/cmd_unmelt.rb +3 -3
  36. data/lib/tb/cmd_unnest.rb +5 -4
  37. data/lib/tb/cmdmain.rb +3 -3
  38. data/lib/tb/cmdtop.rb +3 -3
  39. data/lib/tb/cmdutil.rb +3 -3
  40. data/lib/tb/csv.rb +10 -4
  41. data/lib/tb/customcmp.rb +3 -3
  42. data/lib/tb/customeq.rb +3 -3
  43. data/lib/tb/enumerable.rb +3 -3
  44. data/lib/tb/enumerator.rb +3 -3
  45. data/lib/tb/ex_enumerable.rb +2 -2
  46. data/lib/tb/ex_enumerator.rb +4 -4
  47. data/lib/tb/fieldset.rb +3 -3
  48. data/lib/tb/fileenumerator.rb +6 -6
  49. data/lib/tb/func.rb +3 -3
  50. data/lib/tb/json.rb +3 -3
  51. data/lib/tb/ltsv.rb +32 -7
  52. data/lib/tb/pnm.rb +3 -3
  53. data/lib/tb/reader.rb +3 -3
  54. data/lib/tb/record.rb +3 -3
  55. data/lib/tb/revcmp.rb +3 -3
  56. data/lib/tb/ropen.rb +23 -23
  57. data/lib/tb/search.rb +7 -7
  58. data/lib/tb/tsv.rb +3 -3
  59. data/lib/tb/zipper.rb +3 -3
  60. data/sample/excel2csv +36 -36
  61. data/sample/poi-xls2csv.rb +78 -78
  62. data/sample/poi-xls2csv.sh +3 -3
  63. data/sample/tbplot +214 -112
  64. data/test/test_basic.rb +4 -4
  65. data/test/test_cmd_newfield.rb +17 -3
  66. data/test/test_ex_enumerable.rb +18 -18
  67. data/test/test_ltsv.rb +8 -0
  68. metadata +5 -5
@@ -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
@@ -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', '_["a"].to_i + _["b"].to_i', i])
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 test_no_newfield_ruby_exp
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
@@ -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
 
@@ -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.8'
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-03-29 00:00:00.000000000 Z
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.0.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.'