tb 0.9 → 1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. checksums.yaml +4 -4
  2. data/README +13 -11
  3. data/lib/tb.rb +14 -6
  4. data/lib/tb/catreader.rb +2 -2
  5. data/lib/tb/cmd_consecutive.rb +6 -2
  6. data/lib/tb/cmd_crop.rb +22 -3
  7. data/lib/tb/cmd_cross.rb +24 -0
  8. data/lib/tb/cmd_cut.rb +20 -10
  9. data/lib/tb/cmd_git.rb +20 -7
  10. data/lib/tb/cmd_group.rb +32 -0
  11. data/lib/tb/cmd_gsub.rb +21 -0
  12. data/lib/tb/cmd_join.rb +28 -0
  13. data/lib/tb/cmd_ls.rb +9 -0
  14. data/lib/tb/cmd_melt.rb +15 -0
  15. data/lib/tb/cmd_mheader.rb +15 -0
  16. data/lib/tb/cmd_nest.rb +27 -6
  17. data/lib/tb/cmd_newfield.rb +19 -2
  18. data/lib/tb/cmd_rename.rb +20 -0
  19. data/lib/tb/{cmd_grep.rb → cmd_search.rb} +37 -23
  20. data/lib/tb/cmd_shape.rb +69 -25
  21. data/lib/tb/cmd_sort.rb +20 -0
  22. data/lib/tb/cmd_tar.rb +38 -0
  23. data/lib/tb/cmd_to_json.rb +2 -2
  24. data/lib/tb/cmd_to_ltsv.rb +3 -3
  25. data/lib/tb/cmd_to_pnm.rb +3 -3
  26. data/lib/tb/cmd_to_tsv.rb +3 -3
  27. data/lib/tb/cmd_to_yaml.rb +3 -3
  28. data/lib/tb/cmd_unmelt.rb +15 -0
  29. data/lib/tb/cmd_unnest.rb +31 -7
  30. data/lib/tb/cmdmain.rb +2 -0
  31. data/lib/tb/cmdtop.rb +1 -1
  32. data/lib/tb/cmdutil.rb +9 -62
  33. data/lib/tb/csv.rb +21 -79
  34. data/lib/tb/enumerable.rb +42 -68
  35. data/lib/tb/enumerator.rb +15 -7
  36. data/lib/tb/{fieldset.rb → hashreader.rb} +37 -56
  37. data/lib/tb/hashwriter.rb +54 -0
  38. data/lib/tb/headerreader.rb +108 -0
  39. data/lib/tb/headerwriter.rb +116 -0
  40. data/lib/tb/json.rb +17 -15
  41. data/lib/tb/ltsv.rb +35 -96
  42. data/lib/tb/ndjson.rb +63 -0
  43. data/lib/tb/numericreader.rb +66 -0
  44. data/lib/tb/numericwriter.rb +61 -0
  45. data/lib/tb/pnm.rb +206 -200
  46. data/lib/tb/ropen.rb +54 -59
  47. data/lib/tb/tsv.rb +39 -71
  48. data/sample/excel2csv +24 -25
  49. data/sample/poi-xls2csv.rb +13 -14
  50. data/tb.gemspec +154 -0
  51. data/test/test_cmd_cat.rb +28 -6
  52. data/test/test_cmd_consecutive.rb +8 -3
  53. data/test/test_cmd_cut.rb +14 -4
  54. data/test/test_cmd_git_log.rb +50 -50
  55. data/test/test_cmd_grep.rb +6 -6
  56. data/test/test_cmd_gsub.rb +7 -2
  57. data/test/test_cmd_ls.rb +70 -62
  58. data/test/test_cmd_shape.rb +43 -6
  59. data/test/test_cmd_svn_log.rb +26 -27
  60. data/test/test_cmd_to_csv.rb +10 -5
  61. data/test/test_cmd_to_json.rb +16 -0
  62. data/test/test_cmd_to_ltsv.rb +2 -2
  63. data/test/test_cmd_to_pp.rb +7 -2
  64. data/test/test_csv.rb +74 -62
  65. data/test/test_ex_enumerable.rb +0 -1
  66. data/test/test_fileenumerator.rb +3 -3
  67. data/test/test_headercsv.rb +43 -0
  68. data/test/test_json.rb +2 -2
  69. data/test/test_ltsv.rb +22 -17
  70. data/test/test_ndjson.rb +62 -0
  71. data/test/test_numericcsv.rb +36 -0
  72. data/test/test_pnm.rb +69 -70
  73. data/test/test_reader.rb +27 -124
  74. data/test/test_tbenum.rb +18 -18
  75. data/test/test_tsv.rb +21 -32
  76. data/test/util_tbtest.rb +12 -0
  77. metadata +41 -19
  78. data/lib/tb/basic.rb +0 -1070
  79. data/lib/tb/reader.rb +0 -106
  80. data/lib/tb/record.rb +0 -158
  81. data/test/test_basic.rb +0 -403
  82. data/test/test_fieldset.rb +0 -42
  83. data/test/test_record.rb +0 -61
@@ -1,42 +0,0 @@
1
- require 'test/unit'
2
-
3
- class TestTbFieldSet < Test::Unit::TestCase
4
- def test_new
5
- assert_equal([], Tb::FieldSet.new.header)
6
- assert_equal(['a'], Tb::FieldSet.new('a').header)
7
- assert_equal(['a', 'b'], Tb::FieldSet.new('a', 'b').header)
8
- end
9
-
10
- def test_index_from_field
11
- assert_equal(0, Tb::FieldSet.new('a').index_from_field('a'))
12
- assert_equal(0, Tb::FieldSet.new('a', 'b').index_from_field('a'))
13
- assert_equal(1, Tb::FieldSet.new('a', 'b').index_from_field('b'))
14
- assert_raise(ArgumentError) { Tb::FieldSet.new('a', 'b').index_from_field('c') }
15
- end
16
-
17
- def test_field_from_index_ex
18
- fs = Tb::FieldSet.new('a', 'b')
19
- assert_equal('a', fs.field_from_index_ex(0))
20
- assert_equal('b', fs.field_from_index_ex(1))
21
- assert_equal('1', fs.field_from_index_ex(2))
22
- assert_equal('2', fs.field_from_index_ex(3))
23
- end
24
-
25
- def test_field_from_index
26
- fs = Tb::FieldSet.new('a', 'b')
27
- assert_equal('a', fs.field_from_index(0))
28
- assert_equal('b', fs.field_from_index(1))
29
- assert_raise(ArgumentError) { fs.field_from_index(2) }
30
- end
31
-
32
- def test_length
33
- fs = Tb::FieldSet.new('a', 'b')
34
- assert_equal(2, fs.length)
35
- end
36
-
37
- def test_numsuffix
38
- fs = Tb::FieldSet.new('a', 'a(2)', 'a')
39
- assert_equal(['a', 'a(2)', 'a(3)'], fs.header)
40
- end
41
-
42
- end
@@ -1,61 +0,0 @@
1
- require 'tb'
2
- require 'test/unit'
3
-
4
- class TestTbRecord < Test::Unit::TestCase
5
- def test_pretty_print
6
- t = Tb.new %w[fruit color],
7
- %w[apple red],
8
- %w[banana yellow],
9
- %w[orange orange]
10
- s = t.get_record(0).pretty_inspect
11
- assert_match(/apple/, s)
12
- assert_match(/red/, s)
13
- end
14
-
15
- def test_has_field?
16
- t = Tb.new %w[fruit color],
17
- %w[apple red],
18
- %w[banana yellow],
19
- %w[orange orange]
20
- r = t.get_record(0)
21
- assert_equal(true, r.has_field?("fruit"))
22
- assert_equal(false, r.has_field?("price"))
23
- end
24
-
25
- def test_to_a
26
- t = Tb.new %w[fruit color],
27
- %w[apple red],
28
- %w[banana yellow],
29
- %w[orange orange]
30
- assert_equal([["fruit", "apple"], ["color", "red"]], t.get_record(0).to_a)
31
- end
32
-
33
- def test_to_a_with_reserved
34
- t = Tb.new %w[fruit color],
35
- %w[apple red],
36
- %w[banana yellow],
37
- %w[orange orange]
38
- assert_equal([["_recordid", 0], ["fruit", "apple"], ["color", "red"]], t.get_record(0).to_a_with_reserved)
39
- end
40
-
41
- def test_each_with_reserved
42
- t = Tb.new %w[fruit color],
43
- %w[apple red],
44
- %w[banana yellow],
45
- %w[orange orange]
46
- result = []
47
- t.get_record(0).each_with_reserved {|r|
48
- result << r
49
- }
50
- assert_equal([["_recordid", 0], ["fruit", "apple"], ["color", "red"]], result)
51
- end
52
-
53
- def test_values_at
54
- t = Tb.new %w[fruit color],
55
- %w[apple red],
56
- %w[banana yellow],
57
- %w[orange orange]
58
- assert_equal(["apple", "red"], t.get_record(0).values_at("fruit", "color"))
59
- end
60
-
61
- end