tb 0.9 → 1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README +13 -11
- data/lib/tb.rb +14 -6
- data/lib/tb/catreader.rb +2 -2
- data/lib/tb/cmd_consecutive.rb +6 -2
- data/lib/tb/cmd_crop.rb +22 -3
- data/lib/tb/cmd_cross.rb +24 -0
- data/lib/tb/cmd_cut.rb +20 -10
- data/lib/tb/cmd_git.rb +20 -7
- data/lib/tb/cmd_group.rb +32 -0
- data/lib/tb/cmd_gsub.rb +21 -0
- data/lib/tb/cmd_join.rb +28 -0
- data/lib/tb/cmd_ls.rb +9 -0
- data/lib/tb/cmd_melt.rb +15 -0
- data/lib/tb/cmd_mheader.rb +15 -0
- data/lib/tb/cmd_nest.rb +27 -6
- data/lib/tb/cmd_newfield.rb +19 -2
- data/lib/tb/cmd_rename.rb +20 -0
- data/lib/tb/{cmd_grep.rb → cmd_search.rb} +37 -23
- data/lib/tb/cmd_shape.rb +69 -25
- data/lib/tb/cmd_sort.rb +20 -0
- data/lib/tb/cmd_tar.rb +38 -0
- data/lib/tb/cmd_to_json.rb +2 -2
- data/lib/tb/cmd_to_ltsv.rb +3 -3
- data/lib/tb/cmd_to_pnm.rb +3 -3
- data/lib/tb/cmd_to_tsv.rb +3 -3
- data/lib/tb/cmd_to_yaml.rb +3 -3
- data/lib/tb/cmd_unmelt.rb +15 -0
- data/lib/tb/cmd_unnest.rb +31 -7
- data/lib/tb/cmdmain.rb +2 -0
- data/lib/tb/cmdtop.rb +1 -1
- data/lib/tb/cmdutil.rb +9 -62
- data/lib/tb/csv.rb +21 -79
- data/lib/tb/enumerable.rb +42 -68
- data/lib/tb/enumerator.rb +15 -7
- data/lib/tb/{fieldset.rb → hashreader.rb} +37 -56
- data/lib/tb/hashwriter.rb +54 -0
- data/lib/tb/headerreader.rb +108 -0
- data/lib/tb/headerwriter.rb +116 -0
- data/lib/tb/json.rb +17 -15
- data/lib/tb/ltsv.rb +35 -96
- data/lib/tb/ndjson.rb +63 -0
- data/lib/tb/numericreader.rb +66 -0
- data/lib/tb/numericwriter.rb +61 -0
- data/lib/tb/pnm.rb +206 -200
- data/lib/tb/ropen.rb +54 -59
- data/lib/tb/tsv.rb +39 -71
- data/sample/excel2csv +24 -25
- data/sample/poi-xls2csv.rb +13 -14
- data/tb.gemspec +154 -0
- data/test/test_cmd_cat.rb +28 -6
- data/test/test_cmd_consecutive.rb +8 -3
- data/test/test_cmd_cut.rb +14 -4
- data/test/test_cmd_git_log.rb +50 -50
- data/test/test_cmd_grep.rb +6 -6
- data/test/test_cmd_gsub.rb +7 -2
- data/test/test_cmd_ls.rb +70 -62
- data/test/test_cmd_shape.rb +43 -6
- data/test/test_cmd_svn_log.rb +26 -27
- data/test/test_cmd_to_csv.rb +10 -5
- data/test/test_cmd_to_json.rb +16 -0
- data/test/test_cmd_to_ltsv.rb +2 -2
- data/test/test_cmd_to_pp.rb +7 -2
- data/test/test_csv.rb +74 -62
- data/test/test_ex_enumerable.rb +0 -1
- data/test/test_fileenumerator.rb +3 -3
- data/test/test_headercsv.rb +43 -0
- data/test/test_json.rb +2 -2
- data/test/test_ltsv.rb +22 -17
- data/test/test_ndjson.rb +62 -0
- data/test/test_numericcsv.rb +36 -0
- data/test/test_pnm.rb +69 -70
- data/test/test_reader.rb +27 -124
- data/test/test_tbenum.rb +18 -18
- data/test/test_tsv.rb +21 -32
- data/test/util_tbtest.rb +12 -0
- metadata +41 -19
- data/lib/tb/basic.rb +0 -1070
- data/lib/tb/reader.rb +0 -106
- data/lib/tb/record.rb +0 -158
- data/test/test_basic.rb +0 -403
- data/test/test_fieldset.rb +0 -42
- data/test/test_record.rb +0 -61
data/test/test_fieldset.rb
DELETED
@@ -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
|
data/test/test_record.rb
DELETED
@@ -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
|